Patch for "accept-language" passthrough to cgi

Erich Schubert <[email protected]> Thu, 23 Sep 2004 14:11:02 +0200
Newsgroups gmane.comp.web.fnord
Message-ID <[email protected]>
Hi,
the following patch adds support for passing the "accept-language"
field to a CGI (which can then do language negotiation)
On the long run, it would of course be nice to add negotiation support
to fnord itself, but since i don't need that myself i didn't do it here
but in my CGI... ;-)

Here's the patch:

diff -Nru fnord-1.8/httpd.c fnord/httpd.c
--- fnord-1.8/httpd.c	2003-06-03 19:09:25.000000000 +0200
+++ fnord/httpd.c	2004-08-05 15:52:52.000000000 +0200
@@ -130,6 +130,7 @@
 char *url;			/* string between GET and HTTP/1.0, demangled */
 char *ua=3D"?";			/* user-agent */
 char *refer;			/* Referrer: header */
+char *lang;			/* Accept-Language: header */
 int httpversion;		/* 0 =3D=3D 1.0, 1 =3D=3D 1.1 */
 #ifdef KEEPALIVE
 int keepalive=3D0;		/* should we keep the connection alive? */
@@ -334,6 +335,13 @@
     *tmp=3D0; ++tmp;
   }
=20
+  if (lang) {
+    cgi_env[++i]=3Dtmp;
+    tmp+=3Dstr_copy(tmp,"HTTP_ACCEPT_LANGUAGE=3D");
+    tmp+=3Dstr_copy(tmp,lang);
+    *tmp=3D0; ++tmp;
+  }
+
   if (auth_type) {
     cgi_env[++i]=3Dtmp;
     tmp+=3Dstr_copy(tmp,"AUTH_TYPE=3D");
@@ -1290,6 +1298,7 @@
     char *tmp;
     if ((tmp=3Dheader(buf,len,"User-Agent"))) ua=3Dtmp;
     if ((tmp=3Dheader(buf,len,"Referer"))) refer=3Dtmp;
+    if ((tmp=3Dheader(buf,len,"Accept-Language"))) lang=3Dtmp;
 #ifdef KEEPALIVE
     if ((tmp=3Dheader(buf,len,"Connection"))) {	/* see if it's "keep-ali=
ve" or "close" */
       if (!strcasecmp(tmp,"keep-alive"))


I see that i havn't checked what happens if no Accept-Language header
was given. Maybe the first diff line should be something like lang=3D"";

Greetings,
Erich Schubert
--=20
     erich@(vitavonni.de|debian.org)    --    GPG Key ID: 4B3A135C     (o=
_
 A man doesn't know what he knows until he knows what he doesn't know. //=
\
     Jede Frau erwartet von einem Mann, dass er h=E4lt, was sie sich     =
V_/_
                           von ihm verspricht.