Check-in [9e274a2e7b]
Not logged in
Overview

SHA1 Hash:9e274a2e7bc97635edb085425cd8548a8b72df45
Date: 2009-09-12 21:53:24
User: drh
Comment:Update the proxy handler so that it supports basic authorization.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/http.c from [3ced5594d2] to [2787a16cdc].

@@ -90,10 +90,13 @@
     zSep = "";
   }else{
     zSep = "/";
   }
   blob_appendf(pHdr, "POST %s%sxfer HTTP/1.1\r\n", g.urlPath, zSep);
+  if( g.urlProxyAuth ){
+    blob_appendf(pHdr, "Proxy-Authorization: %s\n", g.urlProxyAuth);
+  }
   blob_appendf(pHdr, "Host: %s\r\n", g.urlHostname);
   blob_appendf(pHdr, "User-Agent: Fossil/" MANIFEST_VERSION "\r\n");
   if( g.fHttpTrace ){
     blob_appendf(pHdr, "Content-Type: application/x-fossil-debug\r\n");
   }else{

Modified src/main.c from [97f8036e59] to [e990b4f28d].

@@ -98,10 +98,11 @@
   int urlDfltPort;        /* The default port for the given protocol */
   char *urlPath;          /* Pathname for http: */
   char *urlUser;          /* User id for http: */
   char *urlPasswd;        /* Password for http: */
   char *urlCanonical;     /* Canonical representation of the URL */
+  char *urlProxyAuth;     /* Proxy-Authorizer: string */
 
   const char *zLogin;     /* Login name.  "" if not logged in. */
   int noPswd;             /* Logged in without password (on 127.0.0.1) */
   int userUid;            /* Integer user id */
 

Modified src/url.c from [17c0d4bc8a] to [c5cf8d9b2a].

@@ -27,17 +27,21 @@
 #include "url.h"
 
 /*
 ** Parse the given URL.  Populate variables in the global "g" structure.
 **
-**      g.urlIsFile      True if this is a file URL
-**      g.urlName        Hostname for HTTP:.  Filename for FILE:
-**      g.urlPort        Port name for HTTP.
-**      g.urlPath        Path name for HTTP.
+**      g.urlIsFile      True if FILE:
+**      g.urlIsHttps     True if HTTPS:
+**      g.urlProtocol    "http" or "https" or "file"
+**      g.urlName        Hostname for HTTP: or HTTPS:.  Filename for FILE:
+**      g.urlPort        TCP port number for HTTP or HTTPS.
+**      g.urlDfltPort    Default TCP port number (80 or 443).
+**      g.urlPath        Path name for HTTP or HTTPS.
 **      g.urlUser        Userid.
 **      g.urlPasswd      Password.
-**      g.urlCanonical   The URL in canonical form
+**      g.urlHostname    HOST:PORT or just HOST if port is the default.
+**      g.urlCanonical   The URL in canonical form, omitting userid/password
 **
 ** HTTP url format is:
 **
 **     http://userid:password@host:port/path?query#fragment
 **
@@ -159,32 +163,38 @@
     }
   }
 }
 
 /*
-** Proxy specified on the command-line.
+** Proxy specified on the command-line using the --proxy option.
+** If there is no --proxy option on the command-line then this
+** variable holds a NULL pointer.
 */
 static const char *zProxyOpt = 0;
 
 /*
-** Extra any proxy options from the command-line.
+** Extract any proxy options from the command-line.
 **
 **    --proxy URL|off
 **
+** This also happens to be a convenient function to use to look for
+** the --nosync option that will temporarily disable the "autosync"
+** feature.
 */
 void url_proxy_options(void){
   zProxyOpt = find_option("proxy", 0, 1);
   if( find_option("nosync",0,0) ) g.fNoSync = 1;
 }
 
 /*
-** If the "proxy" setting is defined, then change the URL to refer
-** to the proxy server.
+** If the "proxy" setting is defined, then change the URL settings
+** (initialized by a prior call to url_parse()) so that the HTTP
+** header will be appropriate for the proxy and so that the TCP/IP
+** connection will be opened to the proxy rather than to the server.
 **
-** If the protocol is "https://" then start stunnel to handle the SSL
-** and make the url setting refer to stunnel rather than the original
-** destination.
+** If zMsg is not NULL and a proxy is used, then print zMsg followed
+** by the canonical name of the proxy (with userid and password suppressed).
 */
 void url_enable_proxy(const char *zMsg){
   const char *zProxy;
   zProxy = zProxyOpt;
   if( zProxy==0 ){
@@ -194,14 +204,26 @@
     }
   }
   if( zProxy && zProxy[0] && !is_false(zProxy) ){
     char *zOriginalUrl = g.urlCanonical;
     char *zOriginalHost = g.urlHostname;
-    if( zMsg ) printf("%s%s\n", zMsg, zProxy);
+    char *zOriginalUser = g.urlUser;
+    char *zOriginalPasswd = g.urlPasswd;
+    g.urlUser = 0;
+    g.urlPasswd = "";
     url_parse(zProxy);
+    if( zMsg ) printf("%s%s\n", zMsg, g.urlCanonical);
     g.urlPath = zOriginalUrl;
     g.urlHostname = zOriginalHost;
+    if( g.urlUser ){
+      char *zCredentials1 = mprintf("%s:%s", g.urlUser, g.urlPasswd);
+      char *zCredentials2 = encode64(zCredentials1, -1);
+      g.urlProxyAuth = mprintf("Basic %z", zCredentials2);
+      free(zCredentials1);
+    }
+    g.urlUser = zOriginalUser;
+    g.urlPasswd = zOriginalPasswd;
   }
 }
 
 #if INTERFACE
 /*