summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert James Kaes <rjkaes@users.sourceforge.net>2002-04-12 03:09:04 +0000
committerRobert James Kaes <rjkaes@users.sourceforge.net>2002-04-12 03:09:04 +0000
commitf1a451faea1206acd262acc473b0f767f0cefb81 (patch)
tree0415ef6a91e723fb9fa8c1f3c3bcb1e9ab55e6cd
parent604785be666156f6b43700a6cbcee36f5568845a (diff)
downloadtinyproxy-f1a451faea1206acd262acc473b0f767f0cefb81.tar.gz
tinyproxy-f1a451faea1206acd262acc473b0f767f0cefb81.zip
Added a write_via_header() function which is now used in both header
processing functions. Also, added a list of headers to drop in the process server header functions.
-rw-r--r--ChangeLog7
-rw-r--r--src/reqs.c107
2 files changed, 73 insertions, 41 deletions
diff --git a/ChangeLog b/ChangeLog
index 93f6597..b779f2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,9 +10,14 @@
(process_server_headers): Rewrote this function to handle the
headers in a more consistent manner. The connection header is
handled correctly, and the content-length header is stored for
- later use.
+ later use. Also, include a list of headers to not send.
(relay_connection): Added a test to use the
connptr->remote_content_length value if it's present.
+ (write_via_header): Moved the creation/modification of the Via
+ header into it's own function since it's used by both
+ process_client_headers() and process_server_headers(). I still
+ need to add code to allow you to "hide" the host information if
+ you so choose.
* src/conns.c: Added the remote_content_length variable to hold
the number of bytes the remove server is _supposed_ to send to
diff --git a/src/reqs.c b/src/reqs.c
index 1e1857f..5244b9d 100644
--- a/src/reqs.c
+++ b/src/reqs.c
@@ -1,4 +1,4 @@
-/* $Id: reqs.c,v 1.55 2002-04-11 20:44:15 rjkaes Exp $
+/* $Id: reqs.c,v 1.56 2002-04-12 03:09:04 rjkaes Exp $
*
* This is where all the work in tinyproxy is actually done. Incoming
* connections have a new thread created for them. The thread then
@@ -497,9 +497,8 @@ get_all_headers(int fd, hashmap_t hashofheaders)
ssize_t len;
for (;;) {
- if ((len = readline(fd, &header)) <= 0) {
+ if ((len = readline(fd, &header)) <= 0)
return -1;
- }
/*
* If we received just a CR LF on a line, the headers are
@@ -536,9 +535,8 @@ remove_connection_headers(hashmap_t hashofheaders)
* a NULL.
*/
ptr = data;
- while ((ptr = strpbrk(ptr, "()<>@,;:\\\"/[]?={} \t"))) {
+ while ((ptr = strpbrk(ptr, "()<>@,;:\\\"/[]?={} \t")))
*ptr++ = '\0';
- }
/*
* All the tokens are separated by NULLs. Now go through the tokens
@@ -546,7 +544,6 @@ remove_connection_headers(hashmap_t hashofheaders)
*/
ptr = data;
while (ptr < data + len) {
- DEBUG2("Removing header [%s]", ptr);
hashmap_remove(hashofheaders, ptr);
/* Advance ptr to the next token */
@@ -573,14 +570,51 @@ get_content_length(hashmap_t hashofheaders)
long content_length = -1;
len = hashmap_search(hashofheaders, "content-length", (void **)&data);
- if (len > 0) {
+ if (len > 0)
content_length = atol(data);
- }
return content_length;
}
/*
+ * Search for Via head in a hash of headers and either write a new Via header,
+ * or append our information to the end of an existing Via header.
+ *
+ * FIXME: Need to add code to "hide" our internal information for security
+ * purposes.
+ */
+static void
+write_via_header(int fd, hashmap_t hashofheaders,
+ unsigned int major, unsigned int minor)
+{
+ ssize_t len;
+ char hostname[128];
+ char *data;
+
+ gethostname(hostname, sizeof(hostname));
+
+ /*
+ * See if there is a "Via" header. If so, again we need to do a bit
+ * of processing.
+ */
+ len = hashmap_search(hashofheaders, "via", (void **)&data);
+ if (len > 0) {
+ write_message(fd,
+ "Via: %s, %hu.%hu %s (%s/%s)\r\n",
+ data,
+ major, minor,
+ hostname, PACKAGE, VERSION);
+
+ hashmap_remove(hashofheaders, "via");
+ } else {
+ write_message(fd,
+ "Via: %hu.%hu %s (%s/%s)\r\n",
+ major, minor,
+ hostname, PACKAGE, VERSION);
+ }
+}
+
+/*
* Number of buckets to use internally in the hashmap.
*/
#define HEADER_BUCKETS 32
@@ -596,7 +630,6 @@ process_client_headers(struct conn_s *connptr)
{
static char *skipheaders[] = {
"host",
- "connection",
"keep-alive",
"proxy-authenticate",
"proxy-authorization",
@@ -651,40 +684,16 @@ process_client_headers(struct conn_s *connptr)
remove_connection_headers(hashofheaders);
/*
- * See if there is a "Via" header. If so, again we need to do a bit
- * of processing.
- */
- len = hashmap_search(hashofheaders, "via", (void **)&data);
- if (len > 0) {
- /* Take on our information */
- char hostname[128];
- gethostname(hostname, sizeof(hostname));
-
- write_message(connptr->server_fd,
- "Via: %s, %hu.%hu %s (%s/%s)\r\n",
- data,
- connptr->protocol.major, connptr->protocol.minor,
- hostname, PACKAGE, VERSION);
-
- hashmap_remove(hashofheaders, "via");
- } else {
- /* There is no header, so we need to create it. */
- char hostname[128];
- gethostname(hostname, sizeof(hostname));
-
- write_message(connptr->server_fd,
- "Via: %hu.%hu %s (%s/%s)\r\n",
- connptr->protocol.major, connptr->protocol.minor,
- hostname, PACKAGE, VERSION);
- }
-
- /*
* Delete the headers listed in the skipheaders list
*/
for (i = 0; i < (sizeof(skipheaders) / sizeof(char *)); i++) {
hashmap_remove(hashofheaders, skipheaders[i]);
}
+ /* Send, or add the Via header */
+ write_via_header(connptr->server_fd, hashofheaders,
+ connptr->protocol.major, connptr->protocol.minor);
+
/*
* Output all the remaining headers to the remote machine.
*/
@@ -730,6 +739,13 @@ process_client_headers(struct conn_s *connptr)
static int
process_server_headers(struct conn_s *connptr)
{
+ static char *skipheaders[] = {
+ "keep-alive",
+ "proxy-authenticate",
+ "proxy-authorization",
+ "transfer-encoding",
+ };
+
char *response_line;
hashmap_t hashofheaders;
@@ -760,6 +776,10 @@ process_server_headers(struct conn_s *connptr)
return -1;
}
+ /* Send the saved response line first */
+ safe_write(connptr->client_fd, response_line, strlen(response_line));
+ safefree(response_line);
+
/*
* If there is a "Content-Length" header, retrieve the information
* from it for later use.
@@ -772,9 +792,16 @@ process_server_headers(struct conn_s *connptr)
*/
remove_connection_headers(hashofheaders);
- /* Send the saved response line first */
- safe_write(connptr->client_fd, response_line, strlen(response_line));
- safefree(response_line);
+ /*
+ * Delete the headers listed in the skipheaders list
+ */
+ for (i = 0; i < (sizeof(skipheaders) / sizeof(char *)); i++) {
+ hashmap_remove(hashofheaders, skipheaders[i]);
+ }
+
+ /* Send, or add the Via header */
+ write_via_header(connptr->client_fd, hashofheaders,
+ connptr->protocol.major, connptr->protocol.minor);
/*
* Okay, output all the remaining headers to the client.