hurl

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 99bd976e6b50ef2d2987e71bd095833161a00022
parent 6005eab8a62903cc88275b4c8cd587e9bcd0c3be
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri, 13 Dec 2019 14:50:40 +0100

add -H option to add one or more headers

This option is back again since it is useful.
Also sort the options and improve the man page a bit.

Diffstat:
Mhurl.1 | 18++++++++++++------
Mhurl.c | 17+++++++++++++----
2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/hurl.1 b/hurl.1 @@ -1,4 +1,4 @@ -.Dd November 16, 2018 +.Dd December 13, 2019 .Dt HURL 1 .Os .Sh NAME @@ -6,8 +6,9 @@ .Nd HTTP/HTTPS/Gopher file grabber .Sh SYNOPSIS .Nm -.Op Fl m Ar filesize +.Op Fl h ar headers .Op Fl l +.Op Fl m Ar filesize .Op Fl t Ar timeout .Ar url .Sh DESCRIPTION @@ -18,10 +19,14 @@ supports the protocols: HTTP, HTTPS and Gopher. .Pp The options are as follows: .Bl -tag -width Ds -.It Fl m Ar filesize -Maximum size of the data in bytes. +.It Fl H Ar headers +Add headers to HTTP or HTTPS requests. +This is the raw data appended to the request. +This can be multiple lines, but the last line should not end with CR LF. .It Fl l Enable legacy ciphers and negotiation for TLS (default off). +.It Fl m Ar filesize +Maximum size of the data in bytes. .It Fl t Ar timeout Maximum time for the connection and fetching the data in seconds. The default is 10 seconds. @@ -29,8 +34,9 @@ The default is 10 seconds. .Pp For HTTP and HTTPS it will write the data except the header to stdout when the HTTP statuscode is "200 OK" and exit with statuscode 0 when all data is -successfully written. When the header is retrieved but it is not "200 OK" it -will write the HTTP header to stderr and exit with a non-zero statuscode. +successfully written. +When the header is retrieved but it is not "200 OK" it will write the HTTP +header to stderr and exit with a non-zero statuscode. .Pp For Gopher it will write the data to stdout and exit with statuscode 0 when all data is successfully written. diff --git a/hurl.c b/hurl.c @@ -39,6 +39,8 @@ struct uri { char *argv0; +/* raw header(s) to add */ +static const char *config_headers = ""; /* max response size in bytes, 0 is unlimited */ static size_t config_maxresponsesiz = 0; /* time-out in seconds */ @@ -211,9 +213,11 @@ https_request(void) "GET %s HTTP/1.0\r\n" "Host: %s%s%s\r\n" "Connection: close\r\n" + "%s%s" "\r\n", u.path, u.host, stdport ? "" : ":", - stdport ? "" : u.port); + stdport ? "" : u.port, + config_headers, config_headers[0] ? "\r\n" : ""); if ((r = tls_write(t, buf, strlen(buf))) < 0) { fprintf(stderr, "tls_write: %s\n", tls_error(t)); goto err; @@ -319,9 +323,11 @@ http_request(void) "GET %s HTTP/1.0\r\n" "Host: %s%s%s\r\n" "Connection: close\r\n" + "%s%s" "\r\n", u.path, u.host, stdport ? "" : ":", - stdport ? "" : u.port); + stdport ? "" : u.port, + config_headers, config_headers[0] ? "\r\n" : ""); if ((r = write(fd, buf, strlen(buf))) == -1) { fprintf(stderr, "write: %s\n", strerror(errno)); goto err; @@ -457,8 +463,8 @@ err: void usage(void) { - fprintf(stderr, "usage: %s [-l] [-m maxresponse] [-t timeout] url\n", - argv0); + fprintf(stderr, "usage: %s [-H headers] [-l] [-m maxresponse] " + "[-t timeout] url\n", argv0); exit(1); } @@ -470,6 +476,9 @@ main(int argc, char **argv) long long l; ARGBEGIN { + case 'H': /* header(s) */ + config_headers = EARGF(usage()); + break; case 'l': /* legacy ciphers */ config_legacy = 1; break;