Add support for HTTP/1.1 name-based virtual hosts. Also, use

asprintf(3) when creating the request string, as the length of
a path is defined as unlimited by the standard and limiting the
total request to 4K is awfully arbitrary.

PR:		30054
Submitted by:	Joseph Mallett <jmallett@xMach.org>
MFC after:	8 days
This commit is contained in:
mike 2001-08-30 00:57:35 +00:00
parent 497cd6cff0
commit e37b33abc6

View File

@ -104,7 +104,7 @@ url_get(origline, proxyenv)
char *port;
volatile int s;
size_t len;
char c, *cp, *ep, *portnum, *path, buf[4096];
char c, *cp, *ep, *http_buffer, *portnum, *path, buf[4096];
const char *savefile;
char *line, *proxy, *host;
volatile sig_t oldintr;
@ -276,20 +276,25 @@ url_get(origline, proxyenv)
* Construct and send the request. We're expecting a return
* status of "200". Proxy requests don't want leading /.
*/
if (!proxy)
if (!proxy) {
printf("Requesting %s\n", origline);
else
len = asprintf(&http_buffer,
"GET /%s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n", path, host);
} else {
printf("Requesting %s (via %s)\n", origline, proxyenv);
len = snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n",
proxy ? "" : "/", path);
if (len < 0 || len >= sizeof(buf)) {
len = asprintf(&http_buffer,
"GET %s HTTP/1.0\r\n\r\n", path);
}
if (len < 0) {
warnx("Failed to format HTTP request");
goto cleanup_url_get;
}
if (write(s, buf, len) < len) {
if (write(s, http_buffer, len) < len) {
warn("Writing HTTP request");
free(http_buffer);
goto cleanup_url_get;
}
free(http_buffer);
memset(buf, 0, sizeof(buf));
for (cp = buf; cp < buf + sizeof(buf); ) {
if (read(s, cp, 1) != 1)