cgmnlm

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/cgmnlm.git
Log | Files | Refs | README | LICENSE

commit 4dd50ac07e82dfc1785f98a3535109e2d738029d
parent 7e4e43b05c298aa812027bf1921ce3f224e86bda
Author: k1nkreet <polyakovskiy.ilya@gmail.com>
Date:   Tue, 15 Jun 2021 19:37:56 +0300

gmni: headers are not displayed for REDIRECT and INPUT responses in SHOW_HEADERS and ONLY_HEADERS modes

I've noticed headers are not displayed in some cases with -i/-I
specified. For example:

echo "printf" | gmni -i gemini://drewdevault.com/cgi-bin/man.sh
Output: empty

echo "printf" | gmni -IL gemini://drewdevault.com/cgi-bin/man.sh -
Output: 10 Search for a POSIX man page
INPUT header is here, but no REDIRECT header appeared.

The reason is headers processing is done after responses dispatch. So
some responses (redirect and input) are processed and dropped before.
Patch makes this logic a bit clearer imho: print response header before
any processing if mode is not OMIT_HEADERS and then process response body if mode
is not ONLY_HEADERS. It also deduplicates header printing as a bonus.

Diffstat:
Msrc/gmni.c | 13+++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/gmni.c b/src/gmni.c @@ -290,6 +290,10 @@ main(int argc, char *argv[]) goto next; } + if (header_mode != OMIT_HEADERS) { + printf("%d %s\n", resp.status, resp.meta); + } + switch (gemini_response_class(resp.status)) { case GEMINI_STATUS_CLASS_INPUT: if (input_mode == INPUT_SUPPRESS) { @@ -351,14 +355,7 @@ main(int argc, char *argv[]) break; } - switch (header_mode) { - case ONLY_HEADERS: - printf("%d %s\n", resp.status, resp.meta); - break; - case SHOW_HEADERS: - printf("%d %s\n", resp.status, resp.meta); - /* fallthrough */ - case OMIT_HEADERS: + if (header_mode != ONLY_HEADERS) { if (gemini_response_class(resp.status) != GEMINI_STATUS_CLASS_SUCCESS) { break;