Cryptography Reference
In-Depth Information
{
// non-standard proxy port
*colon_sep = '\0';
*proxy_host = proxy_spec;
*proxy_port = atoi( colon_sep + 1 );
if ( *proxy_port == 0 )
{
// 0 is not a valid port; this is an error, whether
// it was mistyped or specified as 0.
return 0;
}
}
else
{
*proxy_port = HTTP_PORT;
*proxy_host = proxy_spec;
}
return 1;
}
The port number is also optional. If there's a : character before the end of
the proxy specifi cation, it denotes a port; otherwise, assume the standard HTTP
port 80.
At this point, you have all the pieces you need for HTTP proxy support except
for the changes to the actual http_get routine. Remember that, in ordinary,
“proxy-less” HTTP, you start by establishing a connection to the target HTTP
host and then send in a GET /path HTTP/1.0 request line. However, when
connecting to a proxy, you need to send a whole hostname because the socket
itself has just been established between the client and the proxy. The request
line becomes GET http://host/path HTTP/1.0 . Change http_get as shown
in Listing 1-13 to recognize this case and send a proxy-friendly GET command
if a proxy host parameter was supplied.
Listing 1-13: http_get (modifi ed for proxy support)
int http_get( int connection,
const char *path,
const char *host,
const char *proxy_host,
const char *proxy_user,
const char *proxy_password )
{
static char get_command[ MAX_GET_COMMAND ];
if ( proxy_host )
{
sprintf( get_command, “GET http://%s/%s HTTP/1.1\r\n”, host, path );
}
else
{
 
Search WWH ::




Custom Search