}
static void
-prepareAcceleratedURL(ConnStateData * conn, ClientHttpRequest *http, char *url, const char *req_hdr)
+prepareAcceleratedURL(ConnStateData * conn, ClientHttpRequest *http, char *url, const Http::Http1ParserPointer &hp)
{
int vhost = conn->port->vhost;
int vport = conn->port->vport;
const bool switchedToHttps = conn->switchedToHttps();
const bool tryHostHeader = vhost || switchedToHttps;
- if (tryHostHeader && (host = mime_get_header_field(req_hdr, "Host")) != NULL) {
+ if (tryHostHeader && (host = hp->getHeaderField("Host")) != NULL) {
debugs(33, 5, "ACCEL VHOST REWRITE: vhost=" << host << " + vport=" << vport);
char thost[256];
if (vport > 0) {
}
static void
-prepareTransparentURL(ConnStateData * conn, ClientHttpRequest *http, char *url, const char *req_hdr)
+prepareTransparentURL(ConnStateData * conn, ClientHttpRequest *http, char *url, const Http::Http1ParserPointer &hp)
{
char *host;
char ipbuf[MAX_IPSTRLEN];
/* BUG: Squid cannot deal with '*' URLs (RFC2616 5.1.2) */
- if ((host = mime_get_header_field(req_hdr, "Host")) != NULL) {
+ if ((host = hp->getHeaderField("Host")) != NULL) {
int url_sz = strlen(url) + 32 + Config.appendDomainLen +
strlen(host);
http->uri = (char *)xcalloc(url_sz, 1);
* Process headers after request line
* TODO: Use httpRequestParse here.
*/
- /* XXX this code should be modified to take a const char * later! */
- const char *req_hdr = hp->rawHeaderBuf();
-
- debugs(33, 3, Raw("req_hdr", req_hdr, hp->headerBlockSize()));
-
+ debugs(33, 3, Raw("req_hdr", hp->rawHeaderBuf(), hp->headerBlockSize()));
debugs(33, 3, "prefix_sz = " << hp->messageHeaderSize() <<
", request-line-size=" << hp->firstLineSize() <<
", mime-header-size=" << hp->headerBlockSize());
*/
if (csd->transparent()) {
/* intercept or transparent mode, properly working with no failures */
- prepareTransparentURL(csd, http, url, req_hdr);
+ prepareTransparentURL(csd, http, url, hp);
} else if (internalCheck(url)) {
/* internal URL mode */
} else if (csd->port->flags.accelSurrogate || csd->switchedToHttps()) {
/* accelerator mode */
- prepareAcceleratedURL(csd, http, url, req_hdr);
+ prepareAcceleratedURL(csd, http, url, hp);
}
if (!http->uri) {
return isDone();
}
+
+// arbitrary maximum-length for headers which can be found by Http1Parser::getHeaderField()
+#define GET_HDR_SZ 1024
+
+char *
+Http::Http1Parser::getHeaderField(const char *name)
+{
+ LOCAL_ARRAY(char, header, GET_HDR_SZ);
+ const char *p = NULL;
+ char *q = NULL;
+ char got = 0;
+ const int namelen = name ? strlen(name) : 0;
+
+ if (!headerBlockSize() || !name)
+ return NULL;
+
+ debugs(25, 5, "looking for '" << name << "'");
+
+ for (p = rawHeaderBuf(); *p; p += strcspn(p, "\n\r")) {
+ if (strcmp(p, "\r\n\r\n") == 0 || strcmp(p, "\n\n") == 0)
+ return NULL;
+
+ while (xisspace(*p))
+ ++p;
+
+ if (strncasecmp(p, name, namelen))
+ continue;
+
+ if (!xisspace(p[namelen]) && p[namelen] != ':')
+ continue;
+
+ int l = strcspn(p, "\n\r") + 1;
+
+ if (l > GET_HDR_SZ)
+ l = GET_HDR_SZ;
+
+ xstrncpy(header, p, l);
+
+ debugs(25, 5, "checking '" << header << "'");
+
+ q = header;
+
+ q += namelen;
+
+ if (*q == ':') {
+ ++q;
+ got = 1;
+ }
+
+ while (xisspace(*q)) {
+ ++q;
+ got = 1;
+ }
+
+ if (got) {
+ debugs(25, 5, "returning '" << q << "'");
+ return q;
+ }
+ }
+
+ return NULL;
+}
*/
#include "squid.h"
-
-#define GET_HDR_SZ 1024
#include "Debug.h"
#include "profiler/Profiler.h"
-/*
- * returns a pointer to a field-value of the first matching field-name where
- * field-value matches prefix if any
- */
-char *
-mime_get_header_field(const char *mime, const char *name)
-{
- LOCAL_ARRAY(char, header, GET_HDR_SZ);
- const char *p = NULL;
- char *q = NULL;
- char got = 0;
- const int namelen = name ? strlen(name) : 0;
- int l;
-
- if (NULL == mime)
- return NULL;
-
- assert(NULL != name);
-
- debugs(25, 5, "mime_get_header: looking for '" << name << "'");
-
- for (p = mime; *p; p += strcspn(p, "\n\r")) {
- if (strcmp(p, "\r\n\r\n") == 0 || strcmp(p, "\n\n") == 0)
- return NULL;
-
- while (xisspace(*p))
- ++p;
-
- if (strncasecmp(p, name, namelen))
- continue;
-
- if (!xisspace(p[namelen]) && p[namelen] != ':')
- continue;
-
- l = strcspn(p, "\n\r") + 1;
-
- if (l > GET_HDR_SZ)
- l = GET_HDR_SZ;
-
- xstrncpy(header, p, l);
-
- debugs(25, 5, "mime_get_header: checking '" << header << "'");
-
- q = header;
-
- q += namelen;
-
- if (*q == ':') {
- ++q;
- got = 1;
- }
-
- while (xisspace(*q)) {
- ++q;
- got = 1;
- }
-
- if (got) {
- debugs(25, 5, "mime_get_header: returning '" << q << "'");
- return q;
- }
- }
-
- return NULL;
-}
-
size_t
headersEnd(const char *mime, size_t l)
{