hurl

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

commit ff51a96c8791d2865a559634bffbde3d7e0cc41f
parent b6b313880e857ecf04f6d41ef54ca452b804d1dd
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 10 Nov 2019 14:28:31 +0100

HTTP/HTTPS: send port in Host header if the port is non-standard

Diffstat:
Mhurl.c | 20++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/hurl.c b/hurl.c @@ -178,7 +178,7 @@ https_request(void) const char *errstr; size_t n, len; ssize_t r; - int fd = -1, httpok = 0, ret = 1; + int fd = -1, httpok = 0, ret = 1, stdport; if (pledge("stdio dns inet rpath unveil", NULL) == -1) err(1, "pledge"); @@ -204,12 +204,16 @@ https_request(void) if (pledge("stdio", NULL) == -1) err(1, "pledge"); + stdport = u.port[0] == '\0' || strcmp(u.port, "443") == 0; + /* create and send HTTP header */ snprintf(buf, sizeof(buf), "GET %s HTTP/1.0\r\n" - "Host: %s\r\n" + "Host: %s%s%s\r\n" "Connection: close\r\n" - "\r\n", u.path, u.host); + "\r\n", u.path, u.host, + stdport ? "" : ":", + stdport ? "" : u.port); if ((r = tls_write(t, buf, strlen(buf))) < 0) { fprintf(stderr, "tls_write: %s\n", tls_error(t)); goto err; @@ -298,7 +302,7 @@ http_request(void) char buf[READ_BUF_SIZ], *p; size_t n, len; ssize_t r; - int fd = -1, httpok = 0, ret = 1; + int fd = -1, httpok = 0, ret = 1, stdport; if (pledge("stdio dns inet", NULL) == -1) err(1, "pledge"); @@ -308,12 +312,16 @@ http_request(void) if (pledge("stdio", NULL) == -1) err(1, "pledge"); + stdport = u.port[0] == '\0' || strcmp(u.port, "80") == 0; + /* create and send HTTP header */ snprintf(buf, sizeof(buf), "GET %s HTTP/1.0\r\n" - "Host: %s\r\n" + "Host: %s%s%s\r\n" "Connection: close\r\n" - "\r\n", u.path, u.host); + "\r\n", u.path, u.host, + stdport ? "" : ":", + stdport ? "" : u.port); if ((r = write(fd, buf, strlen(buf))) == -1) { fprintf(stderr, "write: %s\n", strerror(errno)); goto err;