Attached please find a diff against http.c from wget 1.8.2 that
exhibits the correct behavior for https proxies. This can almost definitely
be done better, but this seems to work for me.
Any feedback is greatly appreciated.
--
Gus
"When the shooting starts they always send for the sons-of-bitches."
-- Adm. Ernest King
--- http.c.orig Sun Oct 20 00:29:18 2002
+++ http.c Sat Oct 19 23:58:09 2002
@@ -818,5 +818,5 @@
);
- if (proxy)
+ if (proxy && u->scheme != SCHEME_HTTPS)
full_path = xstrdup (u->url);
else
@@ -826,4 +826,6 @@
full_path = url_full_path (u);
+/* Now send the proxy crap */
+
/* Allocate the memory for the request. */
request = (char *)alloca (strlen (command)
@@ -843,4 +845,134 @@
+ (opt.user_header ? strlen (opt.user_header) : 0)
+ 64);
+
+/* Now send the bogus proxy resuest in this buffer also. */
+ if ( u->scheme == SCHEME_HTTPS && proxy ) {
+ sprintf(request, "CONNECT %s:%d HTTP/1.0\r\n\r\n", u->host, u->port);
+ num_written = iwrite (sock, request, strlen (request));
+
+ if (num_written < 0)
+ {
+ logprintf (LOG_VERBOSE, _("Failed writing HTTP request: %s.\n"),
+ strerror (errno));
+ return WRITEFAILED;
+ }
+ DEBUGP (("---request begin---\n%s---request end---\n", request));
+
+ /* The proxy will also reply. */
+ /* Before reading anything, initialize the rbuf. */
+ rbuf_initialize (&rbuf, sock);
+#ifdef HAVE_SSL
+ if (conn->scheme == SCHEME_HTTPS)
+ rbuf.ssl = ssl;
+ else
+ rbuf.ssl = NULL;
+#endif /* HAVE_SSL */
+ while (1)
+ {
+ char *hdr;
+ int status;
+
+ ++hcount;
+ /* Get the header. */
+ status = header_get (&rbuf, &hdr,
+ /* Disallow continuations for status line. */
+ (hcount == 1 ? HG_NO_CONTINUATIONS : HG_NONE));
+
+ /* Check for errors. */
+ if (status == HG_EOF && *hdr)
+ {
+ /* This used to be an unconditional error, but that was
+ somewhat controversial, because of a large number of
+ broken CGI's that happily "forget" to send the second EOL
+ before closing the connection of a HEAD request.
+
+ So, the deal is to check whether the header is empty
+ (*hdr is zero if it is); if yes, it means that the
+ previous header was fully retrieved, and that -- most
+ probably -- the request is complete. "...be liberal in
+ what you accept." Oh boy. */
+ logputs (LOG_VERBOSE, "\n");
+ logputs (LOG_NOTQUIET, _("End of file while parsing headers.\n"));
+ xfree (hdr);
+ FREE_MAYBE (type);
+ FREE_MAYBE (all_headers);
+ CLOSE_INVALIDATE (sock);
+ return HEOF;
+ }
+ else if (status == HG_ERROR)
+ {
+ logputs (LOG_VERBOSE, "\n");
+ logprintf (LOG_NOTQUIET, _("Read error (%s) in headers.\n"),
+ strerror (errno));
+ xfree (hdr);
+ FREE_MAYBE (type);
+ FREE_MAYBE (all_headers);
+ CLOSE_INVALIDATE (sock);
+ return HERR;
+ }
+
+ /* If the headers are to be saved to a file later, save them to
+ memory now. */
+ if (opt.save_headers)
+ {
+ int lh = strlen (hdr);
+ all_headers = (char *)xrealloc (all_headers, all_length + lh + 2);
+ memcpy (all_headers + all_length, hdr, lh);
+ all_length += lh;
+ all_headers[all_length++] = '\n';
+ all_headers[all_length] = '\0';
+ }
+
+ /* Check for status line. */
+ if (hcount == 1)
+ {
+ const char *error;
+ /* Parse the first line of server response. */
+ statcode = parse_http_status_line (hdr, &error);
+ hs->statcode = statcode;
+ /* Store the descriptive response. */
+ if (statcode == -1) /* malformed response */
+ {
+ /* A common reason for "malformed response" error is the
+ case when no data was actually received. Handle this
+ special case. */
+ if (!*hdr)
+ hs->error = xstrdup (_("No data received"));
+ else
+ hs->error = xstrdup (_("Malformed status line"));
+ xfree (hdr);
+ break;
+ }
+ else if (!*error)
+ hs->error = xstrdup (_("(no description)"));
+ else
+ hs->error = xstrdup (error);
+ }
+
+ /* Exit on empty header. */
+ if (!*hdr)
+ {
+ xfree (hdr);
+ break;
+ }
+ }
+
+
+
+
+conn->scheme = SCHEME_HTTPS;
+keep_alive = 0;
+
+ if (connect_ssl (&ssl, ssl_ctx,sock) != 0)
+ {
+ logputs (LOG_VERBOSE, "\n");
+ logprintf (LOG_NOTQUIET, _("Unable to establish SSL connection.\n"));
+ ssl_printerrors ();
+ CLOSE (sock);
+ return CONSSLERR;
+ }
+
+ }
+
/* Construct the request. */
sprintf (request, "\