From 2de7b8d72b9f8324bd4e07219ca1dc1689ba4614 Mon Sep 17 00:00:00 2001 From: des Date: Tue, 25 Jul 2000 11:45:38 +0000 Subject: Centralize the default port finding code. Work around YA Apache bug: don't send port in Host: header if it's the default port. --- lib/libfetch/http.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'lib/libfetch/http.c') diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c index 0901142..7f6f437 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -600,6 +600,23 @@ _http_authorize(int fd, char *hdr, char *p) */ /* + * Return the default port for this scheme + */ +static int +_http_default_port(char *scheme) +{ + struct servent *se; + + if ((se = getservbyname(scheme, "tcp")) != NULL) + return ntohs(se->s_port); + if (strcasecmp(scheme, "ftp") == 0) + return FTP_DEFAULT_PORT; + if (strcasecmp(scheme, "http") == 0) + return HTTP_DEFAULT_PORT; + return 0; +} + +/* * Connect to the specified HTTP proxy server. */ static int @@ -715,21 +732,8 @@ _http_connect(struct url *URL, int *proxy, char *flags) af = AF_INET6; /* check port */ - if (!URL->port) { - struct servent *se; - - /* Scheme can be ftp if we're using a proxy */ - if (strcasecmp(URL->scheme, "ftp") == 0) - if ((se = getservbyname("ftp", "tcp")) != NULL) - URL->port = ntohs(se->s_port); - else - URL->port = 21; - else - if ((se = getservbyname("http", "tcp")) != NULL) - URL->port = ntohs(se->s_port); - else - URL->port = 80; - } + if (!URL->port) + URL->port = _http_default_port(URL->scheme); if (!direct && (p = getenv("HTTP_PROXY")) != NULL && *p != '\0') { /* attempt to connect to proxy server */ @@ -840,7 +844,10 @@ _http_request(struct url *URL, char *op, struct url_stat *us, char *flags) } /* other headers */ - _http_cmd(fd, "Host: %s:%d", host, url->port); + if (url->port == _http_default_port(url->scheme)) + _http_cmd(fd, "Host: %s", host); + else + _http_cmd(fd, "Host: %s:%d", host, url->port); _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, __progname); if (url->offset) _http_cmd(fd, "Range: bytes=%lld-", url->offset); -- cgit v1.1