]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/HttpHeaderTools.cc
Merged from trunk (r13356).
[thirdparty/squid.git] / src / HttpHeaderTools.cc
index 0f6a2646073f365f9745e6dec69b5829db49c1a4..ce24eed4266760f8767e75e0b3e19d567eeb6459 100644 (file)
@@ -50,7 +50,7 @@
 #include "Store.h"
 #include "StrList.h"
 
-#if USE_SSL
+#if USE_OPENSSL
 #include "ssl/support.h"
 #endif
 
@@ -299,6 +299,36 @@ httpHeaderParseQuotedString(const char *start, const int len, String *val)
     return 1;
 }
 
+// TODO: Optimize using SBuf
+String
+httpHeaderQuoteString(const char *raw)
+{
+    assert(raw);
+
+    // HTTPbis says Senders SHOULD NOT escape octets in quoted-strings that
+    // do not require escaping (i.e., except DQUOTE and the backslash octet).
+    bool needInnerQuote = false;
+    for (const char *s = raw; !needInnerQuote &&  *s; ++s)
+        needInnerQuote = *s == '"' || *s == '\\';
+
+    static String quotedStr;
+    quotedStr.clean();
+    quotedStr.append('"');
+
+    if (needInnerQuote) {
+        for (const char *s = raw; *s; ++s) {
+            if (*s == '"' || *s == '\\')
+                quotedStr.append('\\');
+            quotedStr.append(*s);
+        }
+    } else {
+        quotedStr.append(raw);
+    }
+    
+    quotedStr.append('"');
+    return quotedStr;
+}
+
 /**
  * Checks the anonymizer (header_access) configuration.
  *