[PHP-DEV] HTML proxy support From: Lars Torben Wilson (torben <email protected>)
Date: 07/30/98

I've added HTML proxy support into PHP3 (just about 5 lines in
fopen-wrappers.c and some config stuff). Now, since I have a severe
tendency these days to skip over the exceedingly obvious in search of
the obtuse, I'd like to ask a couple of questions. :)

a) Is this even useful? i.e.--can it be done easier in userland,
   transparently to the script?

b) All it does now is prepend a server name to the GET request--this
   is all the RFC seems to call for. Am I missing something?

Never having really contributed code, here's the patch so I don't
commit something that will crash half the world's PHP sites. I've just
added a configuration option (http_proxy) which, if set, will be
used. (Haven't done anything for module options yet).

Index: fopen-wrappers.c
===================================================================
RCS file: /repository/php3/fopen-wrappers.c,v
retrieving revision 1.39
diff -u -r1.39 fopen-wrappers.c
--- fopen-wrappers.c 1998/06/26 14:58:18 1.39
+++ fopen-wrappers.c 1998/07/24 01:39:24
                 /* use port 80 if one wasn't specified */
                 if (resource->port == 0)
                         resource->port = 80;
@@ -366,7 +367,12 @@
                         free_url(resource);
                         return NULL;
                 }
- server.sin_addr.s_addr = lookup_hostname(resource->host);
+
+ if ( php3_ini.http_proxy != NULL ) {
+ server.sin_addr.s_addr = lookup_hostname(php3_ini.http_proxy);
+ } else {
+ server.sin_addr.s_addr = lookup_hostname(resource->host);
+ }
                 server.sin_family = AF_INET;
 
                 if (server.sin_addr.s_addr == -1) {
@@ -398,11 +404,17 @@
 
                 /* tell remote http which file to get */
                 SOCK_WRITE("GET ", *socketd);
- if (resource->path != NULL) {
- SOCK_WRITE(resource->path, *socketd);
- } else {
- SOCK_WRITE("/", *socketd);
- }
+
+ if ( php3_ini.http_proxy != NULL ) {
+ SOCK_WRITE( "http://", *socketd );
+ SOCK_WRITE( resource->host, *socketd );
+ }
+
+ if (resource->path != NULL) {
+ SOCK_WRITE( resource->path, *socketd );
+ } else {
+ SOCK_WRITE("/", *socketd);
+ }
 
                 /* append the query string, if any */
                 if (resource->query != NULL) {
Index: main.c
===================================================================
RCS file: /repository/php3/main.c,v
retrieving revision 1.453
diff -u -r1.453 main.c
--- main.c 1998/07/12 13:11:58 1.453
+++ main.c 1998/07/24 01:39:38
@@ -955,6 +955,9 @@
                                 php3_ini.include_path = NULL;
                         }
                 }
+ if (cfg_get_string("http_proxy", &php3_ini.http_proxy) == FAILURE) {
+ php3_ini.http_proxy = NULL;
+ }
                 if (cfg_get_string("auto_prepend_file", &php3_ini.auto_prepend_file) == FAILURE) {
                         if ((temp = getenv("PHP_AUTO_PREPEND_FILE"))) {
                                 php3_ini.auto_prepend_file = temp;
Index: mod_php3.h
===================================================================
RCS file: /repository/php3/mod_php3.h,v
retrieving revision 1.40
diff -u -r1.40 mod_php3.h
--- mod_php3.h 1998/07/11 00:57:28 1.40
+++ mod_php3.h 1998/07/24 01:39:39
@@ -59,6 +59,7 @@
     char *isapi_ext;
     char *nsapi_ext;
     char *include_path;
+ char *http_proxy;
     char *auto_prepend_file;
     char *auto_append_file;
     char *upload_tmp_dir;
Index: functions/info.c
===================================================================
RCS file: /repository/php3/functions/info.c,v
retrieving revision 1.61
diff -u -r1.61 info.c
--- info.c 1998/07/18 05:12:48 1.61
+++ info.c 1998/07/24 01:39:47
@@ -153,6 +153,7 @@
         PHP3_CONF_STR("isapi_ext", php3_ini_master.isapi_ext, php3_ini.isapi_ext);
         PHP3_CONF_STR("nsapi_ext", php3_ini_master.nsapi_ext, php3_ini.nsapi_ext);
         PHP3_CONF_STR("include_path", php3_ini_master.include_path, php3_ini.include_path);
+ PHP3_CONF_STR("http_proxy", php3_ini_master.http_proxy, php3_ini.http_proxy);
         PHP3_CONF_STR("auto_prepend_file", php3_ini_master.auto_prepend_file, php3_ini.auto_prepend_file);
         PHP3_CONF_STR("auto_append_file", php3_ini_master.auto_append_file, php3_ini.auto_append_file);
         PHP3_CONF_STR("upload_tmp_dir", php3_ini_master.upload_tmp_dir, php3_ini.upload_tmp_dir);