summaryrefslogtreecommitdiff
path: root/www/urlget/patches/patch-aa
blob: 6e3c7b2604b02db12e5cd59f7e337c10226bad0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
$NetBSD: patch-aa,v 1.1 2000/10/03 11:19:26 agc Exp $

Patches to make urlget honour http_proxy environment setting

--- urlget.c	2000/09/18 13:56:27	1.1
+++ urlget.c	2000/09/18 14:23:37
@@ -91,6 +91,7 @@
   char **postargv = NULL;
   int c, ret, s = 0, count, sawNL;
   int errflg = 0, postflg = 0, hdrflg = 0, oldflg = 0, debug = 0;
+  int isproxy = 0;
   FILE *fp;
 
   while ((c = getopt(argc, argv, "Dhop")) != EOF) {
@@ -131,17 +132,31 @@
   if (strncmp(url, "http:", 5) || (url[5] != '/') || (url[6] != '/'))
     usage(argv[0]);
 
-  if ((path = strchr(host, '/')) == NULL)
-    usage(argv[0]);
-  *path++ = '\0';
-
-  if ((p = strchr(host, ':')) != NULL) {
-    *p++ = '\0';
-    server.sin_port = htons((u_short) atoi(p));
-  } else if ((sp = getservbyname("http", "tcp")) == NULL) {
-    server.sin_port = htons((u_short) DEF_PORT);
+  if ((p = getenv("http_proxy")) == NULL) {
+	if ((path = strchr(host, '/')) == NULL)
+		usage(argv[0]);
+	*path++ = '\0';
+	if ((p = strchr(host, ':')) != NULL) {
+		*p++ = '\0';
+		server.sin_port = htons((u_short) atoi(p));
+	} else if ((sp = getservbyname("http", "tcp")) == NULL) {
+		server.sin_port = htons((u_short) DEF_PORT);
+	} else {
+		server.sin_port = sp->s_port;
+	}
   } else {
-    server.sin_port = sp->s_port;
+	host = &p[7];
+	if ((ep = strchr(host, ':')) == NULL) {
+		server.sin_port = htons((u_short) DEF_PORT);
+	} else {
+		*ep++ = 0;
+		server.sin_port = htons((u_short) atoi(ep));
+	}
+	if ((ep = strrchr(p, '/')) != NULL) {
+		*ep = 0;
+	}
+	path = url;
+	isproxy = 1;
   }
 
   if ((hp = gethostbyname(host)) == NULL) {
@@ -171,7 +186,7 @@
     printf("host = \"%s\", port = %d\n", host, ntohs(server.sin_port));
   }
 
-  fprintf(fp, "%s /%s%s\r\n", cmd, path, oldflg ? "" : " HTTP/1.0");
+  fprintf(fp, "%s %s%s%s\r\n", cmd, (isproxy) ? "" : "/", path, oldflg ? "" : " HTTP/1.0");
   if (!oldflg) {
       fprintf(fp, "Host: %s\r\n", host);
   }