get_destination_from_headers(): Additionally update the request line in proxy format
authorFabian Keil <fk@fabiankeil.de>
Sun, 27 Dec 2015 12:49:29 +0000 (12:49 +0000)
committerFabian Keil <fk@fabiankeil.de>
Sun, 27 Dec 2015 12:49:29 +0000 (12:49 +0000)
This makes rewriting intercepted requests more convenient.

Previously it was expected to fail unless $hostport
was being used, but rewrites of intercepted requests
without $hostport failed "the wrong way" and would
result in an out-of-memory message (vanilla host patterns)
or a crash (extended host patterns).

Reported by "Guybrish Threepwood" in #1694.

parsers.c

index eed559a..7352e8c 100644 (file)
--- a/parsers.c
+++ b/parsers.c
@@ -1,4 +1,4 @@
-const char parsers_rcs[] = "$Id: parsers.c,v 1.299 2015/03/27 12:39:44 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.300 2015/12/27 12:48:59 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/parsers.c,v $
@@ -4445,6 +4445,26 @@ jb_err get_destination_from_headers(const struct list *headers, struct http_requ
    log_error(LOG_LEVEL_HEADER, "Destination extracted from \"Host:\" header. New request URL: %s",
       http->url);
 
+   /*
+    * Regenerate request line in "proxy format"
+    * to make rewrites more convenient.
+    * XXX: Code duplication.
+    */
+   assert(http->cmd != NULL);
+   freez(http->cmd);
+   http->cmd = strdup_or_die(http->gpc);
+   string_append(&http->cmd, " ");
+   string_append(&http->cmd, http->url);
+   string_append(&http->cmd, " ");
+   string_append(&http->cmd, http->ver);
+   if (http->cmd == NULL)
+   {
+      return JB_ERR_MEMORY;
+   }
+
+   log_error(LOG_LEVEL_HEADER, "Faked request-Line: %s",
+      http->cmd);
+
    return JB_ERR_OK;
 
 }