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 fd914b3aa40d63eb7fb2aafb1f6a30c1f78ee92f
parent ee6fe47e44bfb40cd92d6668e85fd893df3a12b8
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 20 Sep 2020 14:18:40 -0400

Implement -L flag (follow redirects)

Diffstat:
Msrc/gmnic.c | 15++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/gmnic.c b/src/gmnic.c @@ -34,7 +34,7 @@ main(int argc, char *argv[]) }; enum input_mode input_mode = INPUT_READ; FILE *input_source = stdin; - bool linefeed = true; + bool follow_redirects = false, linefeed = true; int c; while ((c = getopt(argc, argv, "46C:d:D:hlLiIN")) != -1) { @@ -72,7 +72,7 @@ main(int argc, char *argv[]) linefeed = false; break; case 'L': - assert(0); // TODO: Follow redirects + follow_redirects = true; break; case 'i': header_mode = SHOW_HEADERS; @@ -142,7 +142,16 @@ main(int argc, char *argv[]) url = new_url; goto next; case 3: // REDIRECT - assert(0); // TODO + free(url); + url = strdup(resp.meta); + if (!follow_redirects) { + if (header_mode == OMIT_HEADERS) { + fprintf(stderr, "REDIRECT: %d %s\n", + resp.status, resp.meta); + } + exit = true; + } + goto next; case 6: // CLIENT CERTIFICATE REQUIRED assert(0); // TODO case 4: // TEMPORARY FAILURE