--- mod_encoding.c.apache2.20040616.orig	Wed Jun 16 00:52:25 2004
+++ mod_encoding.c.apache2.20040616	Thu Aug 26 10:37:24 2004
@@ -127,10 +127,60 @@
  ***************************************************************************/
 
 /**
+ * Converts encoding of the input string uri.
+ * Returns NULL on error, else, appropriate string on success.
+ * This function does not convert charcodes after '?' in request line.
+ *
+ * @param r      Apache request object structure
+ * @param cd     Conversion descriptor, made by iconv_open(3).
+ * @param srcbuf Input string
+ * @param srclen Length of the input string. Usually strlen(srcbuf).
+ */
+static char *
+iconv_string_uri(request_rec *r, iconv_t cd, char *srcbuf, size_t srclen) {
+
+  char   *outbuf, *marker;
+  char   *p;
+  size_t  outlen;
+
+  if (srclen == 0) {
+    return srcbuf;
+  }
+
+
+  /* Allocate space for conversion. Note max bloat factor is 4 of UCS-4 */
+  marker = outbuf = (char *)apr_palloc(r->pool, outlen = srclen * 4 + 1);
+
+  if (outbuf == NULL) {
+    return NULL;
+  }
+
+  /* Convert every character within input string. */
+  while (srclen > 0) {
+    if(*srcbuf == '?') break;
+    if (iconv(cd, &srcbuf, &srclen, &outbuf, &outlen) == (size_t)(-1)) {
+      return NULL;
+    }
+  }
+
+#if 0 /* Commented out for now as some iconv seems to break with NULL */
+  /* Everything done. Flush buffer/state and return result */
+  iconv(cd, NULL, NULL, &outbuf, &outlen);
+  iconv(cd, NULL, NULL, NULL, NULL);
+#endif
+
+  /* copy rest of the request line */
+  strcpy(outbuf, srcbuf);
+  /**outbuf = '\0'; */
+
+  return marker;
+}
+
+/**
  * Converts encoding of the input string.
  * Returns NULL on error, else, appropriate string on success.
  *
- * @param p      Memory pool of apache
+ * @param r      Apache request object structure
  * @param cd     Conversion descriptor, made by iconv_open(3).
  * @param srcbuf Input string
  * @param srclen Length of the input string. Usually strlen(srcbuf).
@@ -183,12 +233,25 @@
 iconv_header(request_rec *r, iconv_t cd) {
 
   char *buff;
+  char *p;
   char *keys[] = { "Destination", NULL };
   int   i;
 
   /* Normalize encoding in HTTP request line */
-  ap_unescape_url(r->unparsed_uri);
-  if ((buff = iconv_string(r, cd, r->unparsed_uri,
+
+  p = strchr(r->unparsed_uri, '?');
+  if(!p){
+	  ap_unescape_url(r->unparsed_uri);
+  } else {
+  	char *p2 = p + 1;
+    *p = '\0';
+    ap_unescape_url(r->unparsed_uri);
+    p = strlen(r->unparsed_uri) + r->unparsed_uri;
+    *(p++) = '?';
+    while((*(p++) = *(p2++) ) != '\0');
+  }
+
+  if ((buff = iconv_string_uri(r, cd, r->unparsed_uri,
 			   strlen(r->unparsed_uri))) == NULL)
     return -1;
   ap_parse_uri(r, buff);

