* src/http.c (initialize_request): Send Host HTTP header first

This solves an issue where the server expects the Host: header
as first one. This seems plausible (ahem) as the Host: header is the
only one that is required.
This commit is contained in:
Tim Rühsen
2021-05-03 17:49:54 +02:00
parent 5fe8d26904
commit 027d294114

View File

@@ -1878,6 +1878,27 @@ initialize_request (const struct url *u, struct http_stat *hs, int *dt, struct u
req = request_new (meth, meth_arg);
}
/* Generate the Host header, HOST:PORT. Take into account that:
- Broken server-side software often doesn't recognize the PORT
argument, so we must generate "Host: www.server.com" instead of
"Host: www.server.com:80" (and likewise for https port).
- IPv6 addresses contain ":", so "Host: 3ffe:8100:200:2::2:1234"
becomes ambiguous and needs to be rewritten as "Host:
[3ffe:8100:200:2::2]:1234". */
{
/* Formats arranged for hfmt[add_port][add_squares]. */
static const char *hfmt[][2] = {
{ "%s", "[%s]" }, { "%s:%d", "[%s]:%d" }
};
int add_port = u->port != scheme_default_port (u->scheme);
int add_squares = strchr (u->host, ':') != NULL;
request_set_header (req, "Host",
aprintf (hfmt[add_port][add_squares], u->host, u->port),
rel_value);
}
request_set_header (req, "Referer", hs->referer, rel_none);
if (*dt & SEND_NOCACHE)
{
@@ -1953,27 +1974,6 @@ initialize_request (const struct url *u, struct http_stat *hs, int *dt, struct u
*basic_auth_finished = maybe_send_basic_creds (u->host, *user, *passwd, req);
}
/* Generate the Host header, HOST:PORT. Take into account that:
- Broken server-side software often doesn't recognize the PORT
argument, so we must generate "Host: www.server.com" instead of
"Host: www.server.com:80" (and likewise for https port).
- IPv6 addresses contain ":", so "Host: 3ffe:8100:200:2::2:1234"
becomes ambiguous and needs to be rewritten as "Host:
[3ffe:8100:200:2::2]:1234". */
{
/* Formats arranged for hfmt[add_port][add_squares]. */
static const char *hfmt[][2] = {
{ "%s", "[%s]" }, { "%s:%d", "[%s]:%d" }
};
int add_port = u->port != scheme_default_port (u->scheme);
int add_squares = strchr (u->host, ':') != NULL;
request_set_header (req, "Host",
aprintf (hfmt[add_port][add_squares], u->host, u->port),
rel_value);
}
if (inhibit_keep_alive)
request_set_header (req, "Connection", "Close", rel_none);
else