With this patch patch, you can use ffproxy as accelerating proxy server
(which is quite handy if you want to re-write your headers before they
reach http server).

It includes new command line options -a and -A and configuration
directives accel_host and accel_port.

There is also small fix to compile on Linux (tested with Debian 3.0 unstable)
and fix to allow removing and adding of Host: header.

diff -ur ffproxy-1.4/cache.c ffproxy-1.4+accel/cache.c
--- ffproxy-1.4/cache.c	2003-07-20 13:25:05.000000000 +0200
+++ ffproxy-1.4+accel/cache.c	2003-07-31 00:18:03.000000000 +0200
@@ -28,8 +28,10 @@
 #include <string.h>
 #ifdef LINUX
 #define __USE_GNU 1
-#endif
+#include <asm/fcntl.h>
+#else
 #include <fcntl.h>
+#endif
 #include <unistd.h>
 #include <ctype.h>
 
diff -ur ffproxy-1.4/cfg.h ffproxy-1.4+accel/cfg.h
--- ffproxy-1.4/cfg.h	2003-07-20 11:51:54.000000000 +0200
+++ ffproxy-1.4+accel/cfg.h	2003-07-30 18:09:00.000000000 +0200
@@ -24,4 +24,8 @@
 	unsigned long   cache_max_file_size;
 	int		use_ipv6;
 	int		aux_proxy_ipv6;
+
+	int		use_accel;
+	char		accelhost[256];
+	unsigned int	accelport;
 };
diff -ur ffproxy-1.4/db.c ffproxy-1.4+accel/db.c
--- ffproxy-1.4/db.c	2003-07-20 13:25:05.000000000 +0200
+++ ffproxy-1.4+accel/db.c	2003-07-30 22:23:57.000000000 +0200
@@ -319,6 +319,13 @@
 				else
 					config.use_ipv6 = 0;
 				continue;
+			} else if (strcmp("accel_host", obuf) == 0) {
+				(void) strncpy(config.accelhost, abuf, sizeof(config.accelhost) - 1);
+				config.use_accel = 1;
+				continue;
+			} else if (strcmp("accel_port", obuf) == 0) {
+				config.accelport = atoi(abuf);
+				continue;
 			} else if (*obuf != '#') {
 				warn("unknown option in config file %s:  %s", config.file, obuf);
 				continue;
diff -ur ffproxy-1.4/filter.c ffproxy-1.4+accel/filter.c
--- ffproxy-1.4/filter.c	2003-07-20 13:25:05.000000000 +0200
+++ ffproxy-1.4+accel/filter.c	2003-07-30 23:23:22.000000000 +0200
@@ -41,6 +41,9 @@
 {
 	size_t          i;
 	int             j;
+	char		buf[4096];
+	int		have_host_header = 0;
+	static const char host_header[] = "Host: ";
 
 	i = 0;
 	while (f_host[i] != NULL)
@@ -100,6 +103,18 @@
 
 	debug("filter_request() => added loop header[%d] (%s)", i, r->header[i]);
 
+	// is there Host: header left?
+	j = 0;
+	while (r->header[j] != NULL && j < sizeof(r->header) - 2 && !have_host_header) {
+		if (strncasecmp(r->header[j], host_header, strlen(host_header)) == 0) {
+			have_host_header++;
+			debug("filter_request() => found host header (%d)", have_host_header);
+		}
+
+//		len = snprintf(buf, sizeof(buf), "Host: %s:%d\r\n", r->host, r->port);
+		j++;
+	}
+
 	i++;
 	j = 0;
 	while (f_hdr_add[j] != NULL && i < sizeof(r->header) - 1) {
diff -ur ffproxy-1.4/http.c ffproxy-1.4+accel/http.c
--- ffproxy-1.4/http.c	2003-07-20 13:25:05.000000000 +0200
+++ ffproxy-1.4+accel/http.c	2003-07-30 23:28:41.000000000 +0200
@@ -26,6 +26,7 @@
 #include "req.h"
 #include "print.h"
 #include "http.h"
+#include "cfg.h"
 
 static const char http_get[] = "GET ";
 static const char http_post[] = "POST ";
@@ -38,6 +39,8 @@
 {
 	size_t          i, k;
 	char           *p;
+	extern struct cfg config;
+	char		accelport[10];
 
 	if (strncmp(http_get, s, strlen(http_get)) == 0) {
 		r->type = GET;
@@ -58,26 +61,49 @@
 
 	debug("http_url() => got url part (%s)", s);
 
-	if (strncmp(s, http, strlen(http)) != 0) {
-		r->type = UNKNOWN;
-		return -1;
-	}
+	if (config.use_accel) {
+		debug("http_url() => using as accelerator proxy");
+		i = 0;
+debug("http: %s (%d)", http, strlen(http));
+debug("config.accelhost: %s (%d)", config.accelhost, strlen(config.accelhost));
+		// add http://
+		for (k=0; k<=strlen(http)-1; k++) {
+			r->url[i++] = http[k];
+		}
+		// add hostname (or IP)
+		for (k=0; k<=strlen(config.accelhost)-1; k++) {
+			r->url[i++] = config.accelhost[k];
+		}
+		// add port number
+		r->url[i++] = ':';
+		snprintf(accelport, sizeof(accelport), "%d", config.accelport);
+		for (k=0; k<=strlen(accelport)-1; k++) {
+			r->url[i++] = accelport[k];
+		}
+		r->url[i] = '\0';
+		debug("http_url() => accelerator mode created url (%s)", r->url);
+	} else {
+		if (strncmp(s, http, strlen(http)) != 0) {
+			r->type = UNKNOWN;
+			return -1;
+		}
 
-	i = 0;
-	while (i < strlen(http)) {
-		r->url[i] = http[i];
-		i++, s++;
-	}
+		i = 0;
+		while (i < strlen(http)) {
+			r->url[i] = http[i];
+			i++, s++;
+		}
 
-	while (i < sizeof(r->url) - 1 && *s != '_'
-	       && (isalnum(*s) || *s == '-' || *s == '.' || *s == ':'))
-		r->url[i++] = tolower(*(s++));
-	r->url[i] = '\0';
-	if (*s != '/' && *s != ' ') {
-		r->type = UNKNOWN;
-		return -1;
+		while (i < sizeof(r->url) - 1 && *s != '_'
+		       && (isalnum(*s) || *s == '-' || *s == '.' || *s == ':'))
+			r->url[i++] = tolower(*(s++));
+		r->url[i] = '\0';
+		if (*s != '/' && *s != ' ') {
+			r->type = UNKNOWN;
+			return -1;
+		}
 	}
-
+		
 	k = 0;
 	while (i < sizeof(r->url) - 1 && k < sizeof(r->urlpath) - 1 && *s != ' ' && *s != '\0' && isprint(*s)) {
 		r->urlpath[k++] = *s;
diff -ur ffproxy-1.4/main.c ffproxy-1.4+accel/main.c
--- ffproxy-1.4/main.c	2003-07-20 13:25:05.000000000 +0200
+++ ffproxy-1.4+accel/main.c	2003-07-30 22:23:58.000000000 +0200
@@ -39,7 +39,7 @@
 static void     usage(void);
 static void     drop_privileges(void);
 
-static const char version[] = "1.4";
+static const char version[] = "1.4+accel";
 static const char rcsid[] = "$Id: main.c,v 1.19 2003/07/20 10:54:37 niklas Exp $";
 char            loop_header[100];
 
@@ -71,8 +71,10 @@
 	config.cache_max_file_size = 1024 * 2;
 	config.use_ipv6 = 1;
 	config.aux_proxy_ipv6 = 1;
+	config.use_accel = 0;
+	config.accelport = 80;
 
-	while ((c = getopt(argc, argv, "vdc:p:x:X:l:u:g:r:D:f:s4h")) != -1) {
+	while ((c = getopt(argc, argv, "vdc:p:x:X:l:u:g:r:D:f:s4ha:A:")) != -1) {
 		switch (c) {
 		case 'v':
 			(void) printf("ffproxy version %s, %s\n",
@@ -122,6 +124,14 @@
 		case '4':
 			config.use_ipv6 = 0;
 			break;
+		case 'a':
+			(void) strncpy(config.accelhost, optarg, sizeof(config.accelhost) - 1);
+			config.accelhost[sizeof(config.accelhost) - 1] = '\0';
+			config.use_accel = 1;
+			break;
+		case 'A':
+			config.accelport = atoi(optarg);
+			break;
 		case 'h':
 		default:
 			usage();
@@ -171,6 +181,7 @@
 	(void) fprintf(stderr,
 		       "usage: ffproxy [-vds4h] [-c host|ip] [-p port] [-x host|ip] [-X port] [-l max]\n"
 	      "               [-u uid -g gid] [-r dir] [-D dir] [-f file]\n"
+	      "               [-a host|ip] [-A port]\n"
 		       "\n"
 		       " -v      print version number\n"
 		       " -d      become daemon\n"
@@ -187,7 +198,10 @@
 		       " -g gid      change gid\n"
 		       " -r dir      chroot to dir\n"
 		       " -D dir      databases are in dir\n"
-		       " -f file     use config file\n");
+		       " -f file     use config file\n"
+		       " -a host|ip  auxiliary forward server to use\n"
+		       " -A port     auxiliary forward server port\n"
+		       );
 	exit(1);
 }
 
diff -ur ffproxy-1.4/request.c ffproxy-1.4+accel/request.c
--- ffproxy-1.4/request.c	2003-07-20 13:25:05.000000000 +0200
+++ ffproxy-1.4+accel/request.c	2003-07-31 00:18:50.000000000 +0200
@@ -307,8 +307,7 @@
 			r->vmajor = 1, r->vminor = 0;
 
 		len = snprintf(buf, sizeof(buf),
-			       "%s %s HTTP/%d.%d\r\n"
-			       "Host: %s:%d\r\n",
+			       "%s %s HTTP/%d.%d\r\n",
 			       ((r->type == GET) ? "GET"
 				: ((r->type) == HEAD) ? "HEAD" : "POST"),
 			       (*config.proxyhost && config.proxyport) != '\0' ? r->url :  r->urlpath,
diff -ur ffproxy-1.4/sample.config ffproxy-1.4+accel/sample.config
--- ffproxy-1.4/sample.config	2003-07-20 11:51:38.000000000 +0200
+++ ffproxy-1.4+accel/sample.config	2003-07-30 22:22:37.000000000 +0200
@@ -78,4 +78,10 @@
 # normally you don't need to set that
 #backlog_size 4
 
+# if you want to use ffproxy as http accelerator (that is, connecting
+# to just one http server and beeing used as front-end to that, e.g.
+# in DMZ) uncomments options below (port is optional)
+#accel_host 10.254.1.2
+#accel_port 80
+
 # end of file
