~sircmpwn/gmni-devel

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

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

 1 files changed, 5 insertions(+), 8 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/gmni-devel/patches/23333/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] gmni: headers are not displayed for REDIRECT and INPUT responses in SHOW_HEADERS and ONLY_HEADERS modes Export this patch

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.

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

diff --git a/src/gmni.c b/src/gmni.c
index f3015ac..ff6c619 100644
--- 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;
-- 
2.32.0
Thanks!

To git@git.sr.ht:~sircmpwn/gmni
   9b95e38..b46b312  master -> master