summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/http.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2000-07-25 11:45:38 +0000
committerdes <des@FreeBSD.org>2000-07-25 11:45:38 +0000
commit2de7b8d72b9f8324bd4e07219ca1dc1689ba4614 (patch)
tree11d2f391d90ea74c6b5e72fd1d769d97edc3e6ee /lib/libfetch/http.c
parent64de57e4e28f41b53af571e2f918c940e2286097 (diff)
downloadFreeBSD-src-2de7b8d72b9f8324bd4e07219ca1dc1689ba4614.zip
FreeBSD-src-2de7b8d72b9f8324bd4e07219ca1dc1689ba4614.tar.gz
Centralize the default port finding code.
Work around YA Apache bug: don't send port in Host: header if it's the default port.
Diffstat (limited to 'lib/libfetch/http.c')
-rw-r--r--lib/libfetch/http.c39
1 files changed, 23 insertions, 16 deletions
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);
OpenPOWER on IntegriCloud