Added option to specify additional headers to be sent to the HTTPS proxy

(Ex: --header "MyCustomHeader: MyValue)
Based on Dieter Heiliger's <dieter.heiliger@gmx.de> idea for a User-Agent header


git-svn-id: https://proxytunnel.svn.sourceforge.net/svnroot/proxytunnel/trunk/proxytunnel@39 bc163920-b10d-0410-b2c5-a5491ca2ceef
This commit is contained in:
Mark Janssen 2002-05-14 10:19:56 +00:00
parent 2836cc9ba5
commit 888dce8506
4 changed files with 31 additions and 12 deletions

View file

@ -1,3 +1,10 @@
Changes to proxytunnel version 1.1.1 -- Tue May 14 12:09:07 CEST 2002
- Added a reworked version of Dieter Heiliger's idea to add a switch to
specify a User-Agent header to the CONNECT message. I made it into a
generic 'Header' function, so you can add whatever you like to the
connect string ( --header "MyCustomHeader: Value" )
Changes to proxytunnel version 1.1.0 -- Mon Apr 22 22:58:05 CEST 2002
- Ported new features (like stand-alone mode) to CYGWIN and fixed some

View file

@ -10,6 +10,7 @@ people.
patch, rpm Spec file
Martin Senft <martin@illicon.de> - Solaris patches
Andrew Griffiths <nullptr@tasmail.com> - String format fixes
Dieter Heiliger <dieter.heiliger@gmx.de>- User-agent header idea
Furthermore we would like to thank the wonderful people at SourceForge

View file

@ -59,6 +59,7 @@ cmdline_parser_print_help (void)
-G INT --proxyport=INT HTTPS Proxy portnumber to connect to\n\
-d STRING --desthost=STRING Destination host to built the tunnel to\n\
-D INT --destport=INT Destination portnumber to built the tunnel to\n\
-H STRING --header=STRING Add STRING to HTTP headers sent to proxy\n\
-n --dottedquad Convert destination hostname to dotted quad\n\
-v --verbose Turn on verbosity (default=off)\n\
-q --quiet Suppress messages (default=off)\n\
@ -110,6 +111,7 @@ int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *ar
args_info->verbose_given = 0;
args_info->inetd_given = 0;
args_info->quiet_given = 0;
args_info->header_given = 0;
/* No... we can't make this a function... -- Maniac */
#define clear_args() \
@ -118,6 +120,7 @@ int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *ar
args_info->pass_arg = NULL; \
args_info->proxyhost_arg = NULL; \
args_info->desthost_arg = NULL; \
args_info->header_arg = NULL; \
args_info->dottedquad_flag = 0; \
args_info->verbose_flag = 0; \
args_info->inetd_flag = 0; \
@ -140,6 +143,7 @@ int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *ar
#ifdef HAVE_GETOPT_LONG
int option_index = 0;
/* Struct option: Name, Has_arg, Flag, Value */
static struct option long_options[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'V' },
@ -149,6 +153,7 @@ int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *ar
{ "proxyport", 1, NULL, 'G' },
{ "desthost", 1, NULL, 'd' },
{ "destport", 1, NULL, 'D' },
{ "header", 1, NULL, 'H' },
{ "dottedquad", 0, NULL, 'n' },
{ "verbose", 0, NULL, 'v' },
{ "inetd", 0, NULL, 'i' },
@ -157,9 +162,9 @@ int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *ar
{ NULL, 0, NULL, 0 }
};
c = getopt_long (argc, argv, "hVia:u:s:g:G:d:D:nvq", long_options, &option_index);
c = getopt_long (argc, argv, "hVia:u:s:g:G:d:D:H:nvq", long_options, &option_index);
#else
c = getopt( argc, argv, "hVia:u:s:g:G:d:D:nvq" );
c = getopt( argc, argv, "hVia:u:s:g:G:d:D:H:nvq" );
#endif
if (c == -1) break; /* Exit from `while (1)' loop. */
@ -264,6 +269,12 @@ int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *ar
args_info->destport_arg = atoi (optarg);
break;
case 'H': /* Extra headers to send to HTTPS proxy. */
args_info->header_given++;
/* FIXME in case of multiple headers, later... */
args_info->header_arg = gengetopt_strdup (optarg);
break;
case 'n': /* Turn on resolve to Dotted Quad */
args_info->dottedquad_flag = !(args_info->dottedquad_flag);
break;

20
http.c
View file

@ -96,28 +96,28 @@ void proxy_protocol()
}
sprintf( buf, "CONNECT %s:%d HTTP/1.0\r\n",
args_info.desthost_arg, args_info.destport_arg );
if ( args_info.user_given && args_info.pass_given )
{
/*
* Create connect string including the authorization part
*/
sprintf( buf,
"CONNECT %s:%d HTTP/1.0\r\nProxy-authorization: Basic %s \r\nProxy-Connection: Keep-Alive\r\n\r\n",
args_info.desthost_arg,
args_info.destport_arg,basicauth );
sprintf( buf, "%sProxy-authorization: Basic %s\r\n",
buf, basicauth );
}
else
if ( args_info.header_given )
{
/*
* Create connect string without authorization part
* Add extra header(s)
*/
sprintf( buf, "CONNECT %s:%d HTTP/1.0\r\nProxy-Connection: Keep-Alive\r\n\r\n",
args_info.desthost_arg,
args_info.destport_arg );
sprintf( buf, "%s%s\r\n\r\n", buf, args_info.header_arg );
}
if( args_info.verbose_flag )
message( "%s", buf);
message( "Connect string sent to Proxy: '%s'\n", buf);
/*
* Send the CONNECT instruction to the proxy