From f2f77d87fd956da619e2bed2b24c1542bafe0125 Mon Sep 17 00:00:00 2001 From: hniksic Date: Sun, 19 Nov 2000 16:04:06 -0800 Subject: [PATCH] [svn] New option --no-http-keep-alive. Published in . --- src/ChangeLog | 5 +++++ src/http.c | 23 ++++++++++------------- src/init.c | 2 ++ src/main.c | 7 +++++++ src/options.h | 1 + 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 93af875d..71401675 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2000-11-20 Hrvoje Niksic + + * http.c (gethttp): Don't use the return value of sprintf(). + (gethttp): Inhibit keep-alive if opt.http_keep_alive is 0. + 2000-11-20 Hrvoje Niksic * recur.c (recursive_retrieve): Print the "so we don't load" diff --git a/src/http.c b/src/http.c index 07621acc..f7598031 100644 --- a/src/http.c +++ b/src/http.c @@ -444,9 +444,8 @@ gethttp (struct urlinfo *u, struct http_stat *hs, int *dt) char *authenticate_h; char *proxyauth; char *all_headers; - char *host_port; + char *port_maybe; char *request_keep_alive; - int host_port_len; int sock, hcount, num_written, all_length, remport, statcode; long contlen, contrange; struct urlinfo *ou; @@ -474,7 +473,7 @@ gethttp (struct urlinfo *u, struct http_stat *hs, int *dt) authenticate_h = 0; auth_tried_already = 0; - inhibit_keep_alive = (u->proxy != NULL); + inhibit_keep_alive = (!opt.http_keep_alive || u->proxy != NULL); again: /* We need to come back here when the initial attempt to retrieve @@ -623,15 +622,12 @@ gethttp (struct urlinfo *u, struct http_stat *hs, int *dt) remhost = ou->host; remport = ou->port; - if (remport == 80) + /* String of the form :PORT. Used only for non-standard ports. */ + port_maybe = NULL; + if (remport != 80) { - host_port = NULL; - host_port_len = 0; - } - else - { - host_port = (char *)alloca (numdigit (remport) + 2); - host_port_len = sprintf (host_port, ":%d", remport); + port_maybe = (char *)alloca (numdigit (remport) + 2); + sprintf (port_maybe, ":%d", remport); } if (!inhibit_keep_alive) @@ -642,7 +638,8 @@ gethttp (struct urlinfo *u, struct http_stat *hs, int *dt) /* Allocate the memory for the request. */ request = (char *)alloca (strlen (command) + strlen (path) + strlen (useragent) - + strlen (remhost) + host_port_len + + strlen (remhost) + + (port_maybe ? strlen (port_maybe) : 0) + strlen (HTTP_ACCEPT) + (request_keep_alive ? strlen (request_keep_alive) : 0) @@ -661,7 +658,7 @@ Host: %s%s\r\n\ Accept: %s\r\n\ %s%s%s%s%s%s%s\r\n", command, path, useragent, remhost, - host_port ? host_port : "", + port_maybe ? port_maybe : "", HTTP_ACCEPT, request_keep_alive ? request_keep_alive : "", referer ? referer : "", diff --git a/src/init.c b/src/init.c index b511c724..e7b974f4 100644 --- a/src/init.c +++ b/src/init.c @@ -122,6 +122,7 @@ static struct { { "header", NULL, cmd_spec_header }, { "htmlextension", &opt.html_extension, cmd_boolean }, { "htmlify", NULL, cmd_spec_htmlify }, + { "httpkeepalive", &opt.http_keep_alive, cmd_boolean }, { "httppasswd", &opt.http_passwd, cmd_string }, { "httpproxy", &opt.http_proxy, cmd_string }, { "httpuser", &opt.http_user, cmd_string }, @@ -214,6 +215,7 @@ defaults (void) opt.netrc = 1; opt.ftp_glob = 1; opt.htmlify = 1; + opt.http_keep_alive = 1; opt.use_proxy = 1; tmp = getenv ("no_proxy"); if (tmp) diff --git a/src/main.c b/src/main.c index ca4f7f23..5cbd692b 100644 --- a/src/main.c +++ b/src/main.c @@ -247,6 +247,7 @@ main (int argc, char *const *argv) { "no-directories", no_argument, NULL, 19 }, { "no-host-directories", no_argument, NULL, 20 }, { "no-host-lookup", no_argument, NULL, 22 }, + { "no-http-keep-alive", no_argument, NULL, 28 }, { "no-parent", no_argument, NULL, 5 }, { "non-verbose", no_argument, NULL, 18 }, { "passive-ftp", no_argument, NULL, 11 }, @@ -385,6 +386,9 @@ hpVqvdkKsxmNWrHSLcFbEY:G:g:T:U:O:l:n:i:o:a:t:D:A:R:P:B:e:Q:X:I:w:", case 27: setval ("bindaddress", optarg); break; + case 28: + setval ("httpkeepalive", "off"); + break; case 'b': setval ("background", "on"); break; @@ -579,6 +583,9 @@ GNU General Public License for more details.\n")); case 'p': setval ("noparent", "on"); break; + case 'k': + setval ("httpkeepalive", "off"); + break; default: printf (_("%s: illegal option -- `-n%c'\n"), exec_name, *p); print_usage (); diff --git a/src/options.h b/src/options.h index 742c7547..db849579 100644 --- a/src/options.h +++ b/src/options.h @@ -86,6 +86,7 @@ struct options char *http_user; /* HTTP user. */ char *http_passwd; /* HTTP password. */ char *user_header; /* User-defined header(s). */ + int http_keep_alive; /* whether we use keep-alive */ int use_proxy; /* Do we use proxy? */ int proxy_cache; /* Do we load from proxy cache? */