$OpenBSD: patch-http_c,v 1.2 2003/06/12 13:47:44 brad Exp $
--- http.c.orig	Thu May 22 03:29:13 2003
+++ http.c	Wed Jun  4 09:17:11 2003
@@ -157,6 +157,7 @@ void http_send_header(struct connection 
 	int l = 0;
 	unsigned char *post;
 	unsigned char *host;
+	unsigned char *host_data;
 
 	find_in_cache(c->url, &c->cache);
 
@@ -316,6 +317,13 @@ void http_send_header(struct connection 
 		add_num_to_str(&hdr, &l, c->from);
 		add_to_str(&hdr, &l, "-\r\n");
 	}
+	host_data = find_auth(host);
+	if (host_data) {
+		add_to_str(&hdr, &l, "Authorization: Basic ");
+		add_to_str(&hdr, &l, host_data);
+		add_to_str(&hdr, &l, "\r\n");
+		mem_free(host_data);
+	}
 	if (post) {
 		unsigned char *pd = strchr(post, '\n');
 		if (pd) {
@@ -590,6 +598,22 @@ void http_got_header(struct connection *
 			e->redirect_get = h == 303;
 		}
 	}
+ 	if (h == 401) {
+		d = parse_http_header(e->head, "WWW-Authenticate", NULL);
+		if (d) {
+			if (!strncasecmp(d, "Basic", 5)) {
+				unsigned char *realm = get_http_header_param(d, "realm");
+
+				if (realm) {
+					if (add_auth_entry(host, realm) > 0) {
+                                            need_auth=1;
+                                        }
+					mem_free(realm);
+				}
+			}
+			mem_free(d);
+		}
+  	}
 	kill_buffer_data(rb, a);
 	c->cache = e;
 	info->close = 0;
