aboutsummaryrefslogtreecommitdiffstats
path: root/util/http.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/http.c')
-rw-r--r--util/http.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/util/http.c b/util/http.c
index 173c17116..81bf91ded 100644
--- a/util/http.c
+++ b/util/http.c
@@ -1,5 +1,5 @@
/* http.c - HTTP protocol handler
- * Copyright (C) 1999 Free Software Foundation, Inc.
+ * Copyright (C) 1999, 2000 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -26,7 +26,7 @@
#include <ctype.h>
#include <errno.h>
-#ifndef HAVE_DOSISH_SYSTEM
+#ifndef HAVE_DOSISH_SYSTEM /* fixme: add support W32 sockets */
#include <unistd.h>
#include <sys/types.h>
@@ -76,7 +76,7 @@ http_open( HTTP_HD hd, HTTP_REQ_TYPE reqtype, const char *url,
{
int rc;
- if( flags || !(reqtype == HTTP_REQ_GET || reqtype == HTTP_REQ_POST) )
+ if( !(reqtype == HTTP_REQ_GET || reqtype == HTTP_REQ_POST) )
return GPGERR_INV_ARG;
/* initialize the handle */
@@ -84,6 +84,7 @@ http_open( HTTP_HD hd, HTTP_REQ_TYPE reqtype, const char *url,
hd->sock = -1;
hd->initialized = 1;
hd->req_type = reqtype;
+ hd->flags = flags;
rc = parse_uri( &hd->uri, url );
if( !rc ) {
@@ -150,10 +151,7 @@ http_open_document( HTTP_HD hd, const char *document, unsigned int flags )
{
int rc;
- if( flags )
- return GPGERR_INV_ARG;
-
- rc = http_open( hd, HTTP_REQ_GET, document, 0 );
+ rc = http_open( hd, HTTP_REQ_GET, document, flags );
if( rc )
return rc;
@@ -429,21 +427,47 @@ send_request( HTTP_HD hd )
byte *request, *p;
ushort port;
int rc;
+ const char *http_proxy = NULL;
server = *hd->uri->host? hd->uri->host : "localhost";
port = hd->uri->port? hd->uri->port : 80;
- hd->sock = connect_server( server, port );
+ if( (hd->flags & HTTP_FLAG_TRY_PROXY)
+ && (http_proxy = getenv( "http_proxy" )) ) {
+ PARSED_URI uri;
+
+ rc = parse_uri( &uri, http_proxy );
+ if (rc) {
+ log_error("invalid $http_proxy: %s\n", gpg_errstr(rc));
+ release_parsed_uri( uri );
+ return GPGERR_NETWORK;
+ }
+ hd->sock = connect_server( *uri->host? uri->host : "localhost",
+ uri->port? uri->port : 80 );
+ release_parsed_uri( uri );
+ }
+ else
+ hd->sock = connect_server( server, port );
+
if( hd->sock == -1 )
return GPGERR_NETWORK;
p = build_rel_path( hd->uri );
request = gcry_xmalloc( strlen(p) + 20 );
- sprintf( request, "%s %s%s HTTP/1.0\r\n",
+ if( http_proxy ) {
+ sprintf( request, "%s http://%s:%hu%s%s HTTP/1.0\r\n",
+ hd->req_type == HTTP_REQ_GET ? "GET" :
+ hd->req_type == HTTP_REQ_HEAD? "HEAD":
+ hd->req_type == HTTP_REQ_POST? "POST": "OOPS",
+ server, port, *p == '/'? "":"/", p );
+ }
+ else {
+ sprintf( request, "%s %s%s HTTP/1.0\r\n",
hd->req_type == HTTP_REQ_GET ? "GET" :
hd->req_type == HTTP_REQ_HEAD? "HEAD":
hd->req_type == HTTP_REQ_POST? "POST": "OOPS",
*p == '/'? "":"/", p );
+ }
gcry_free(p);
rc = write_server( hd->sock, request, strlen(request) );