Add support for HTTP proxies, fix some bugs with http transfers.
Submitted-By: Mikael Hybsch <micke@dynas.se>
This commit is contained in:
parent
b2a9728202
commit
477a3f5488
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=17596
@ -1,4 +1,4 @@
|
||||
.\" $Id: fetch.1,v 1.2 1996/07/05 01:03:20 jkh Exp $
|
||||
.\" $Id: fetch.1,v 1.3 1996/07/18 00:07:59 jkh Exp $
|
||||
.Dd July 2, 1996
|
||||
.Dt FETCH 1
|
||||
.Os
|
||||
@ -99,6 +99,14 @@ is the password for the remote host. Default is
|
||||
|
||||
.Ev FTP_PASSIVE_MODE
|
||||
will force the use of passive mode FTP for firewalls.
|
||||
|
||||
If
|
||||
.Ev HTTP_PROXY
|
||||
is set to a value of the form
|
||||
.Em host:port
|
||||
it specifies the address of a http proxy. The proxy will be used
|
||||
for all ftp and http requests. This is useful if you are behind
|
||||
an application firewall.
|
||||
.Sh SEE ALSO
|
||||
.Xr tftp 1
|
||||
.Xr ftp 1
|
||||
|
@ -24,7 +24,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* $Id: main.c,v 1.13 1996/08/07 02:15:26 jkh Exp $ */
|
||||
/* $Id: main.c,v 1.14 1996/08/12 12:55:26 jkh Exp $ */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -60,6 +60,7 @@ char *change_to_dir = 0;
|
||||
char *host = 0;
|
||||
int passive_mode = 0;
|
||||
char *file_to_get = 0;
|
||||
int http_proxy = 0;
|
||||
int http = 0;
|
||||
int http_port = 80;
|
||||
int mirror = 0;
|
||||
@ -71,7 +72,8 @@ FILE *file = 0;
|
||||
void usage (), die (), rm (), t_out (), ftpget (), httpget (),
|
||||
display (int, int), parse (char *), output_file_name(),
|
||||
f_size (char *, int *, time_t *), ftperr (FILE* ftp, char *, ...),
|
||||
filter (unsigned char *, int);
|
||||
filter (unsigned char *, int),
|
||||
setup_http_proxy();
|
||||
int match (char *, char *), http_open ();
|
||||
|
||||
void
|
||||
@ -193,6 +195,8 @@ main (int argc, char **argv)
|
||||
signal (SIGQUIT, die);
|
||||
signal (SIGTERM, die);
|
||||
|
||||
setup_http_proxy();
|
||||
|
||||
if (http)
|
||||
httpget ();
|
||||
else
|
||||
@ -484,7 +488,8 @@ httpget ()
|
||||
restart = 0;
|
||||
|
||||
s = http_open ();
|
||||
sprintf (str, "GET /%s HTTP/1.0\n\n", file_to_get);
|
||||
sprintf (str, "GET %s%s HTTP/1.0\r\n\r\n",
|
||||
http_proxy? "" : "/", file_to_get);
|
||||
i = strlen (str);
|
||||
if (i != write (s, str, i))
|
||||
err (1, "could not send GET command to HTTP server.");
|
||||
@ -580,7 +585,7 @@ filter (unsigned char *p, int len)
|
||||
if (i > 0)
|
||||
size = atoi (s+i);
|
||||
/* assume that the file to get begins after an empty line */
|
||||
i = match (".*(\n\n|\r\n\r\n)", s);
|
||||
i = match ("(\n\n|\r\n\r\n)", s);
|
||||
if (i > 0) {
|
||||
if (s[i] == '\r')
|
||||
t = s+i+4;
|
||||
@ -660,3 +665,43 @@ void msgDebug (char *p)
|
||||
{
|
||||
printf ("%s", p);
|
||||
}
|
||||
|
||||
void
|
||||
setup_http_proxy()
|
||||
{
|
||||
char *e;
|
||||
char *p;
|
||||
char *url;
|
||||
unsigned short port;
|
||||
|
||||
if (!(e = getenv("HTTP_PROXY"))
|
||||
|| !(p = strchr(e, ':'))
|
||||
|| (port = atoi(p+1)) == 0)
|
||||
return;
|
||||
|
||||
if (!(url = (char *) malloc (strlen(file_to_get)
|
||||
+ strlen(host)
|
||||
+ (change_to_dir ? strlen(change_to_dir) : 0)
|
||||
+ 50)))
|
||||
return;
|
||||
|
||||
if (http) {
|
||||
sprintf(url, "http://%s:%d/%s",
|
||||
host, http_port, file_to_get);
|
||||
} else {
|
||||
if (change_to_dir) {
|
||||
sprintf(url, "ftp://%s/%s/%s",
|
||||
host, change_to_dir, file_to_get);
|
||||
} else {
|
||||
sprintf(url, "ftp://%s/%s", host, file_to_get);
|
||||
}
|
||||
}
|
||||
file_to_get = url;
|
||||
|
||||
*p = 0;
|
||||
host = strdup(e);
|
||||
http_port = port;
|
||||
http = 1;
|
||||
http_proxy = 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user