From 7f06a3d8d7e9569685ac575db1a0f6cf5681024a Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Mon, 21 Apr 2014 19:47:09 -0700 Subject: [PATCH] SBuf: convert HttpMethod internals Update the internal string/image representation of an HTTP method to be an SBuf string. Including the global registered methods index. Also, * remove RequestMethodStr() wrapper functions * remove remainders of obsolete extension_methods feature * remove remainders of obsolete RequestMethodStr[] array * fix potential cache key error from http/MethodType.h enum ordering. * polished many debugs involving method --- src/AccessLogEntry.h | 3 +-- src/FwdState.cc | 2 +- src/HttpRequest.cc | 10 ++++----- src/HttpRequestMethod.cc | 33 +++++++++++------------------- src/HttpRequestMethod.h | 25 +++++----------------- src/Makefile.am | 4 ++++ src/MemObject.cc | 3 +-- src/Server.cc | 2 +- src/acl/MethodData.cc | 2 +- src/auth/digest/UserRequest.cc | 6 ++++-- src/cache_diff.cc | 12 ----------- src/client_side.cc | 6 ++---- src/client_side_reply.cc | 13 ++++++------ src/client_side_request.cc | 5 ++--- src/errorpage.cc | 17 +++++++-------- src/external_acl.cc | 6 +++++- src/format/Format.cc | 17 ++++++++++++--- src/htcp.cc | 8 +++++--- src/http.cc | 8 ++++---- src/http/Makefile.am | 2 +- src/http/MethodType.h | 20 ++++++++++-------- src/log/FormatHttpdCombined.cc | 10 +++++++-- src/log/FormatHttpdCommon.cc | 10 +++++++-- src/log/FormatSquidNative.cc | 10 +++++++-- src/log/access_log.cc | 2 +- src/mgr/ActionParams.cc | 2 +- src/mk-string-arrays.awk | 13 +++++++----- src/peer_select.cc | 8 ++++---- src/store_log.cc | 4 ++-- src/test_cache_digest.cc | 12 ----------- src/tests/testHttpRequestMethod.cc | 12 +++++------ src/tunnel.cc | 2 +- 32 files changed, 141 insertions(+), 148 deletions(-) diff --git a/src/AccessLogEntry.h b/src/AccessLogEntry.h index 53a922ee1d..648ffac198 100644 --- a/src/AccessLogEntry.h +++ b/src/AccessLogEntry.h @@ -223,8 +223,7 @@ public: #endif // Why is this a sub-class and not a set of real "private:" fields? - // It looks like its duplicating HTTPRequestMethod anyway! - // TODO: shuffle this to the relevant protocol section OR replace with request->method + // TODO: shuffle this to the relevant ICP/HTCP protocol section class Private { diff --git a/src/FwdState.cc b/src/FwdState.cc index dbc6abeee5..e39f55b3f2 100644 --- a/src/FwdState.cc +++ b/src/FwdState.cc @@ -1203,7 +1203,7 @@ FwdState::connectStart() void FwdState::dispatch() { - debugs(17, 3, HERE << clientConn << ": Fetching '" << RequestMethodStr(request->method) << " " << entry->url() << "'"); + debugs(17, 3, clientConn << ": Fetching " << request->method << ' ' << entry->url()); /* * Assert that server_fd is set. This is to guarantee that fwdState * is attached to something and will be deallocated when server_fd diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 764e71f909..d73f56535f 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -391,8 +391,8 @@ HttpRequest::pack(Packer * p) { assert(p); /* pack request-line */ - packerPrintf(p, "%s " SQUIDSTRINGPH " HTTP/%d.%d\r\n", - RequestMethodStr(method), SQUIDSTRINGPRINT(urlpath), + packerPrintf(p, SQUIDSBUFPH " " SQUIDSTRINGPH " HTTP/%d.%d\r\n", + SQUIDSBUFPRINT(method.image()), SQUIDSTRINGPRINT(urlpath), http_ver.major, http_ver.minor); /* headers */ header.packInto(p); @@ -414,7 +414,7 @@ httpRequestPack(void *obj, Packer *p) int HttpRequest::prefixLen() { - return strlen(RequestMethodStr(method)) + 1 + + return method.image().length() + 1 + urlpath.size() + 1 + 4 + 1 + 3 + 2 + header.len + 2; @@ -524,8 +524,8 @@ const char *HttpRequest::packableURI(bool full_uri) const void HttpRequest::packFirstLineInto(Packer * p, bool full_uri) const { // form HTTP request-line - packerPrintf(p, "%s %s HTTP/%d.%d\r\n", - RequestMethodStr(method), + packerPrintf(p, SQUIDSBUFPH " %s HTTP/%d.%d\r\n", + SQUIDSBUFPRINT(method.image()), packableURI(full_uri), http_ver.major, http_ver.minor); } diff --git a/src/HttpRequestMethod.cc b/src/HttpRequestMethod.cc index 3c4aa54a2c..40c709e69a 100644 --- a/src/HttpRequestMethod.cc +++ b/src/HttpRequestMethod.cc @@ -20,20 +20,11 @@ operator++ (Http::MethodType &aMethod) * or from a range of chars, * such as "GET" from "GETFOOBARBAZ" * (pass in pointer to G and pointer to F.) */ -HttpRequestMethod::HttpRequestMethod(char const *begin, char const *end) : theMethod (Http::METHOD_NONE) +HttpRequestMethod::HttpRequestMethod(char const *begin, char const *end) : theMethod(Http::METHOD_NONE) { if (begin == NULL) return; - /* - * This check for '%' makes sure that we don't - * match one of the extension method placeholders, - * which have the form %EXT[0-9][0-9] - */ - - if (*begin == '%') - return; - /* * if e is NULL, b must be NULL terminated and we * make e point to the first whitespace character @@ -42,40 +33,40 @@ HttpRequestMethod::HttpRequestMethod(char const *begin, char const *end) : theMe if (NULL == end) end = begin + strcspn(begin, w_space); - if (end == begin) { - theMethod = Http::METHOD_NONE; + if (end == begin) return; - } + // TODO: Optimize this linear search. for (++theMethod; theMethod < Http::METHOD_ENUM_END; ++theMethod) { // RFC 2616 section 5.1.1 - Method names are case-sensitive // NP: this is not a HTTP_VIOLATIONS case since there is no MUST/SHOULD involved. - if (0 == strncasecmp(begin, Http::MethodType_str[theMethod], end-begin)) { + if (0 == image().caseCmp(begin, end-begin)) { // relaxed parser allows mixed-case and corrects them on output if (Config.onoff.relaxed_header_parser) return; - if (0 == strncmp(begin, Http::MethodType_str[theMethod], end-begin)) + if (0 == image().cmp(begin, end-begin)) return; } } // if method not found and method string is not null then it is other method theMethod = Http::METHOD_OTHER; - theImage.limitInit(begin,end-begin); + theImage.assign(begin, end-begin); } -char const* +const SBuf & HttpRequestMethod::image() const { + static const SBuf methodOther("METHOD_OTHER"); if (Http::METHOD_OTHER != theMethod) { - return Http::MethodType_str[theMethod]; + return Http::MethodType_sb[theMethod]; } else { - if (theImage.size()>0) { - return theImage.termedBuf(); + if (!theImage.isEmpty()) { + return theImage; } else { - return "METHOD_OTHER"; + return methodOther; } } } diff --git a/src/HttpRequestMethod.h b/src/HttpRequestMethod.h index e6584a4cd8..dc1f88684d 100644 --- a/src/HttpRequestMethod.h +++ b/src/HttpRequestMethod.h @@ -2,8 +2,7 @@ #define SQUID_HTTPREQUESTMETHOD_H #include "http/MethodType.h" -#include "SquidString.h" -#include "SquidString.h" +#include "SBuf.h" class SquidConfig; @@ -41,7 +40,7 @@ public: HttpRequestMethod & operator = (Http::MethodType const aMethod) { theMethod = aMethod; - theImage.clean(); + theImage.clear(); return *this; } @@ -73,8 +72,8 @@ public: */ Http::MethodType id() const { return theMethod; } - /** Get a char string representation of the method. */ - char const * image() const; + /** Get a string representation of the method. */ + const SBuf &image() const; /// Whether this method is defined as a "safe" in HTTP/1.1 /// see RFC 2616 section 9.1.1 @@ -112,10 +111,8 @@ public: bool purgesOthers() const; private: - static const char *RequestMethodStr[]; - Http::MethodType theMethod; ///< Method type - String theImage; ///< Used for storing the Http::METHOD_OTHER only. A copy of the parsed method text. + SBuf theImage; ///< Used for storing the Http::METHOD_OTHER only. A copy of the parsed method text. }; inline std::ostream & @@ -125,16 +122,4 @@ operator << (std::ostream &os, HttpRequestMethod const &method) return os; } -inline const char* -RequestMethodStr(const Http::MethodType m) -{ - return HttpRequestMethod(m).image(); -} - -inline const char* -RequestMethodStr(const HttpRequestMethod& m) -{ - return m.image(); -} - #endif /* SQUID_HTTPREQUESTMETHOD_H */ diff --git a/src/Makefile.am b/src/Makefile.am index 488b6a9ccc..2d88ff027e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3804,6 +3804,9 @@ tests_testStatHist_SOURCES = \ fatal.h \ tests/stub_fatal.cc \ tests/stub_MemBuf.cc \ + $(SBUF_SOURCE) \ + SBufDetailedStats.h \ + tests/stub_SBufDetailedStats.cc \ StatHist.cc \ StatHist.h \ String.cc \ @@ -3822,6 +3825,7 @@ tests_testStatHist_SOURCES = \ repl_modules.h \ tests/stub_store.cc \ tests/stub_store_stats.cc \ + time.cc \ tools.h \ tests/stub_tools.cc \ tests/testMain.cc \ diff --git a/src/MemObject.cc b/src/MemObject.cc index 93051f4767..f0cafba359 100644 --- a/src/MemObject.cc +++ b/src/MemObject.cc @@ -243,8 +243,7 @@ struct StoreClientStats : public unary_function { void MemObject::stat(MemBuf * mb) const { - mb->Printf("\t%s %s\n", - RequestMethodStr(method), logUri()); + mb->Printf("\t" SQUIDSBUFPH " %s\n", SQUIDSBUFPRINT(method.image()), logUri()); if (vary_headers) mb->Printf("\tvary_headers: %s\n", vary_headers); mb->Printf("\tinmem_lo: %" PRId64 "\n", inmem_lo); diff --git a/src/Server.cc b/src/Server.cc index 8438cd2978..324b23315b 100644 --- a/src/Server.cc +++ b/src/Server.cc @@ -517,7 +517,7 @@ ServerStateData::maybePurgeOthers() // XXX: should we use originalRequest() here? const char *reqUrl = urlCanonical(request); - debugs(88, 5, "maybe purging due to " << RequestMethodStr(request->method) << ' ' << reqUrl); + debugs(88, 5, "maybe purging due to " << request->method << ' ' << reqUrl); purgeEntriesByUrl(request, reqUrl); purgeEntriesByHeader(request, reqUrl, theFinalReply, HDR_LOCATION); purgeEntriesByHeader(request, reqUrl, theFinalReply, HDR_CONTENT_LOCATION); diff --git a/src/acl/MethodData.cc b/src/acl/MethodData.cc index e1cd9b6bee..6fad15ef90 100644 --- a/src/acl/MethodData.cc +++ b/src/acl/MethodData.cc @@ -74,7 +74,7 @@ ACLMethodData::dump() const CbDataList *data = values; while (data != NULL) { - sl.push_back(SBuf(RequestMethodStr(data->element))); + sl.push_back(data->element.image()); data = data->next; } diff --git a/src/auth/digest/UserRequest.cc b/src/auth/digest/UserRequest.cc index 3158db9958..76cc980235 100644 --- a/src/auth/digest/UserRequest.cc +++ b/src/auth/digest/UserRequest.cc @@ -102,9 +102,10 @@ Auth::Digest::UserRequest::authenticate(HttpRequest * request, ConnStateData * c authenticateDigestNonceNonceb64(digest_request->nonce), digest_request->cnonce, digest_user->HA1, SESSIONKEY); + SBuf sTmp = request->method.image(); DigestCalcResponse(SESSIONKEY, authenticateDigestNonceNonceb64(digest_request->nonce), digest_request->nc, digest_request->cnonce, digest_request->qop, - RequestMethodStr(request->method), digest_request->uri, HA2, Response); + sTmp.c_str(), digest_request->uri, HA2, Response); debugs(29, 9, "\nResponse = '" << digest_request->response << "'\nsquid is = '" << Response << "'"); @@ -123,9 +124,10 @@ Auth::Digest::UserRequest::authenticate(HttpRequest * request, ConnStateData * c * widespread and such broken browsers no longer are commonly * used. */ + sTmp = HttpRequestMethod(Http::METHOD_GET).image(); DigestCalcResponse(SESSIONKEY, authenticateDigestNonceNonceb64(digest_request->nonce), digest_request->nc, digest_request->cnonce, digest_request->qop, - RequestMethodStr(Http::METHOD_GET), digest_request->uri, HA2, Response); + sTmp.c_str(), digest_request->uri, HA2, Response); if (strcasecmp(digest_request->response, Response)) { auth_user->credentials(Auth::Failed); diff --git a/src/cache_diff.cc b/src/cache_diff.cc index 729b6a9292..99fdb9a53f 100644 --- a/src/cache_diff.cc +++ b/src/cache_diff.cc @@ -59,18 +59,6 @@ typedef struct _CacheEntry { unsigned char key_arr[SQUID_MD5_DIGEST_LENGTH]; } CacheEntry; -/* copied from url.c */ -const char *RequestMethodStr[] = { - "NONE", - "GET", - "POST", - "PUT", - "HEAD", - "CONNECT", - "TRACE", - "PURGE" -}; - static int cacheIndexScan(CacheIndex * idx, const char *fname, FILE * file); static CacheEntry * diff --git a/src/client_side.cc b/src/client_side.cc index 5fa2894764..8ee7bd2eca 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -898,10 +898,8 @@ clientSetKeepaliveFlag(ClientHttpRequest * http) { HttpRequest *request = http->request; - debugs(33, 3, "clientSetKeepaliveFlag: http_ver = " << - request->http_ver.major << "." << request->http_ver.minor); - debugs(33, 3, "clientSetKeepaliveFlag: method = " << - RequestMethodStr(request->method)); + debugs(33, 3, "http_ver = " << request->http_ver); + debugs(33, 3, "method = " << request->method); // TODO: move to HttpRequest::hdrCacheInit, just like HttpReply. request->flags.proxyKeepalive = request->persistent(); diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 9716c0368b..75e0989c01 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -631,7 +631,7 @@ clientReplyContext::processMiss() char *url = http->uri; HttpRequest *r = http->request; ErrorState *err = NULL; - debugs(88, 4, "clientProcessMiss: '" << RequestMethodStr(r->method) << " " << url << "'"); + debugs(88, 4, r->method << ' ' << url); /** * We might have a left-over StoreEntry from a failed cache hit @@ -708,8 +708,7 @@ clientReplyContext::processMiss() void clientReplyContext::processOnlyIfCachedMiss() { - debugs(88, 4, "clientProcessOnlyIfCachedMiss: '" << - RequestMethodStr(http->request->method) << " " << http->uri << "'"); + debugs(88, 4, http->request->method << ' ' << http->uri); http->al->http.code = Http::scGatewayTimeout; ErrorState *err = clientBuildError(ERR_ONLY_IF_CACHED_MISS, Http::scGatewayTimeout, NULL, http->getConn()->clientConnection->remote, http->request); @@ -835,7 +834,7 @@ purgeEntriesByUrl(HttpRequest * req, const char *url) for (HttpRequestMethod m(Http::METHOD_NONE); m != Http::METHOD_ENUM_END; ++m) { if (m.respMaybeCacheable()) { if (StoreEntry *entry = storeGetPublic(url, m)) { - debugs(88, 5, "purging " << *entry << ' ' << RequestMethodStr(m) << ' ' << url); + debugs(88, 5, "purging " << *entry << ' ' << m << ' ' << url); #if USE_HTCP neighborsHtcpClear(entry, url, req, m, HTCP_CLR_INVALIDATION); if (m == Http::METHOD_GET || m == Http::METHOD_HEAD) { @@ -1995,9 +1994,9 @@ clientReplyContext::ProcessReplyAccessResult(allow_t rv, void *voidMe) void clientReplyContext::processReplyAccessResult(const allow_t &accessAllowed) { - debugs(88, 2, "The reply for " << RequestMethodStr(http->request->method) - << " " << http->uri << " is " << accessAllowed << ", because it matched '" - << (AclMatchedName ? AclMatchedName : "NO ACL's") << "'" ); + debugs(88, 2, "The reply for " << http->request->method + << ' ' << http->uri << " is " << accessAllowed << ", because it matched " + << (AclMatchedName ? AclMatchedName : "NO ACL's")); if (accessAllowed != ACCESS_ALLOWED) { ErrorState *err; diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 22b41862f8..a09d072bad 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -758,8 +758,7 @@ ClientRequestContext::clientAccessCheckDone(const allow_t &answer) acl_checklist = NULL; err_type page_id; Http::StatusCode status; - debugs(85, 2, "The request " << - RequestMethodStr(http->request->method) << " " << + debugs(85, 2, "The request " << http->request->method << ' ' << http->uri << " is " << answer << "; last ACL checked: " << (AclMatchedName ? AclMatchedName : "[none]")); @@ -1516,7 +1515,7 @@ ClientRequestContext::sslBumpAccessCheckDone(const allow_t &answer) void ClientHttpRequest::processRequest() { - debugs(85, 4, "clientProcessRequest: " << RequestMethodStr(request->method) << " '" << uri << "'"); + debugs(85, 4, request->method << ' ' << uri); if (request->method == Http::METHOD_CONNECT && !redirect.status) { #if USE_OPENSSL diff --git a/src/errorpage.cc b/src/errorpage.cc index 8f72807078..a5db9d94ff 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -764,8 +764,8 @@ ErrorState::Dump(MemBuf * mb) else urlpath_or_slash = "/"; - str.Printf("%s " SQUIDSTRINGPH " %s/%d.%d\n", - RequestMethodStr(request->method), + str.Printf(SQUIDSBUFPH " " SQUIDSTRINGPH " %s/%d.%d\n", + SQUIDSBUFPRINT(request->method.image()), SQUIDSTRINGPRINT(urlpath_or_slash), AnyP::ProtocolType_str[request->http_ver.protocol], request->http_ver.major, request->http_ver.minor); @@ -940,10 +940,11 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion break; case 'M': - if (request) - p = RequestMethodStr(request->method); - else if (!building_deny_info_url) - p= "[unknown method]"; + if (request) { + const SBuf &m = request->method.image(); + mb.append(m.rawContent(), m.length()); + } else if (!building_deny_info_url) + p = "[unknown method]"; break; case 'o': @@ -983,8 +984,8 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion else urlpath_or_slash = "/"; - mb.Printf("%s " SQUIDSTRINGPH " %s/%d.%d\n", - RequestMethodStr(request->method), + mb.Printf(SQUIDSBUFPH " " SQUIDSTRINGPH " %s/%d.%d\n", + SQUIDSBUFPRINT(request->method.image()), SQUIDSTRINGPRINT(urlpath_or_slash), AnyP::ProtocolType_str[request->http_ver.protocol], request->http_ver.major, request->http_ver.minor); diff --git a/src/external_acl.cc b/src/external_acl.cc index 97ce564af3..3fc75227a9 100644 --- a/src/external_acl.cc +++ b/src/external_acl.cc @@ -1058,7 +1058,11 @@ makeExternalAclKey(ACLFilledChecklist * ch, external_acl_data * acl_data) break; case _external_acl_format::EXT_ACL_METHOD: - str = RequestMethodStr(request->method); + { + const SBuf &s = request->method.image(); + sb.append(s.rawContent(), s.length()); + } + str = sb.termedBuf(); break; case _external_acl_format::EXT_ACL_HEADER_REQUEST: diff --git a/src/format/Format.cc b/src/format/Format.cc index bc85d32179..2cc39d0778 100644 --- a/src/format/Format.cc +++ b/src/format/Format.cc @@ -916,7 +916,9 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS case LFT_CLIENT_REQ_METHOD: if (al->request) { - out = al->request->method.image(); + const SBuf &s = al->request->method.image(); + sb.append(s.rawContent(), s.length()); + out = sb.termedBuf(); quote = 1; } break; @@ -952,7 +954,14 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS break; case LFT_REQUEST_METHOD: - out = al->_private.method_str; + if (al->_private.method_str) // ICP, HTCP method code + out = al->_private.method_str; + else { + const SBuf &s = al->http.method.image(); + sb.append(s.rawContent(), s.length()); + out = sb.termedBuf(); + quote = 1; + } break; case LFT_REQUEST_URI: @@ -967,7 +976,9 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS case LFT_SERVER_REQ_METHOD: if (al->adapted_request) { - out = al->adapted_request->method.image(); + const SBuf &s = al->adapted_request->method.image(); + sb.append(s.rawContent(), s.length()); + out = sb.termedBuf(); quote = 1; } break; diff --git a/src/htcp.cc b/src/htcp.cc index 4ad6678bac..4f4a0a9fcd 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -168,7 +168,7 @@ public: void setFrom(Ip::Address &from); void setDataHeader(htcpDataHeader *); - char *method; + const char *method; char *uri; char *version; char *req_hdrs; @@ -1577,7 +1577,8 @@ htcpQuery(StoreEntry * e, HttpRequest * req, CachePeer * p) stuff.f1 = 1; stuff.response = 0; stuff.msg_id = ++msg_id_counter; - stuff.S.method = (char *) RequestMethodStr(req->method); + SBuf sb = req->method.image(); + stuff.S.method = sb.c_str(); stuff.S.uri = (char *) e->url(); stuff.S.version = vbuf; HttpStateData::httpBuildRequestHeader(req, e, NULL, &hdr, flags); @@ -1640,7 +1641,8 @@ htcpClear(StoreEntry * e, const char *uri, HttpRequest * req, const HttpRequestM stuff.reason = 0; break; } - stuff.S.method = (char *) RequestMethodStr(req->method); + SBuf sb = req->method.image(); + stuff.S.method = sb.c_str(); if (e == NULL || e->mem_obj == NULL) { if (uri == NULL) { return; diff --git a/src/http.cc b/src/http.cc index 76b2b06817..f860a4299d 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1046,7 +1046,7 @@ HttpStateData::statusIfComplete() const * connection. */ if (!flags.request_sent) { - debugs(11, 2, "statusIfComplete: Request not yet fully sent \"" << RequestMethodStr(request->method) << " " << entry->url() << "\"" ); + debugs(11, 2, "Request not yet fully sent " << request->method << ' ' << entry->url()); return COMPLETE_NONPERSISTENT_MSG; } @@ -2117,8 +2117,8 @@ HttpStateData::buildRequestPrefix(MemBuf * mb) url = urlCanonical(request); else url = request->urlpath.termedBuf(); - mb->Printf("%s %s %s/%d.%d\r\n", - RequestMethodStr(request->method), + mb->Printf(SQUIDSBUFPH " %s %s/%d.%d\r\n", + SQUIDSBUFPRINT(request->method.image()), url && *url ? url : "/", AnyP::ProtocolType_str[httpver.protocol], httpver.major,httpver.minor); @@ -2269,7 +2269,7 @@ HttpStateData::getMoreRequestBody(MemBuf &buf) void httpStart(FwdState *fwd) { - debugs(11, 3, "httpStart: \"" << RequestMethodStr(fwd->request->method) << " " << fwd->entry->url() << "\"" ); + debugs(11, 3, fwd->request->method << ' ' << fwd->entry->url()); AsyncJob::Start(new HttpStateData(fwd)); } diff --git a/src/http/Makefile.am b/src/http/Makefile.am index 7c7530bd1a..d329dac284 100644 --- a/src/http/Makefile.am +++ b/src/http/Makefile.am @@ -13,7 +13,7 @@ libsquid_http_la_SOURCES = \ StatusLine.h MethodType.cc: MethodType.h $(top_srcdir)/src/mk-string-arrays.awk - ($(AWK) -f $(top_srcdir)/src/mk-string-arrays.awk < $(srcdir)/MethodType.h | \ + ($(AWK) -f $(top_srcdir)/src/mk-string-arrays.awk sbuf=1 < $(srcdir)/MethodType.h | \ sed -e 's%METHOD_%%' -e 's%_C%-C%' >$@) || ($(RM) -f $@ && exit 1) CLEANFILES += MethodType.cc diff --git a/src/http/MethodType.h b/src/http/MethodType.h index fbe811e419..a586df287b 100644 --- a/src/http/MethodType.h +++ b/src/http/MethodType.h @@ -1,6 +1,8 @@ #ifndef SQUID_SRC_HTTP_METHODTYPE_H #define SQUID_SRC_HTTP_METHODTYPE_H +#include "SBuf.h" + namespace Http { @@ -11,12 +13,6 @@ namespace Http typedef enum _method_t { METHOD_NONE = 0, -#if NO_SPECIAL_HANDLING - // RFC 2068 - METHOD_LINK, - METHOD_UNLINK, -#endif - // RFC 2616 (HTTP) METHOD_GET, METHOD_POST, @@ -27,6 +23,12 @@ typedef enum _method_t { METHOD_OPTIONS, METHOD_DELETE, +#if NO_SPECIAL_HANDLING + // RFC 2068 + METHOD_LINK, + METHOD_UNLINK, +#endif + // RFC 3253 METHOD_CHECKOUT, METHOD_CHECKIN, @@ -83,12 +85,12 @@ typedef enum _method_t { METHOD_ENUM_END // MUST be last, (yuck) this is used as an array-initialization index constant! } MethodType; -extern const char *MethodType_str[]; +extern const SBuf MethodType_sb[]; -inline const char* +inline const SBuf & MethodStr(const MethodType m) { - return MethodType_str[m]; + return MethodType_sb[m]; } }; // namespace Http diff --git a/src/log/FormatHttpdCombined.cc b/src/log/FormatHttpdCombined.cc index 4c19d3e3ec..55c231561a 100644 --- a/src/log/FormatHttpdCombined.cc +++ b/src/log/FormatHttpdCombined.cc @@ -67,12 +67,18 @@ Log::Format::HttpdCombined(const AccessLogEntry::Pointer &al, Logfile * logfile) char clientip[MAX_IPSTRLEN]; al->getLogClientIp(clientip, MAX_IPSTRLEN); - logfilePrintf(logfile, "%s %s %s [%s] \"%s %s %s/%d.%d\" %d %" PRId64 " \"%s\" \"%s\" %s%s:%s%s", + static SBuf method; + if (al->_private.method_str) + method.assign(al->_private.method_str); + else + method = al->http.method.image(); + + logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " %s %s/%d.%d\" %d %" PRId64 " \"%s\" \"%s\" %s%s:%s%s", clientip, user_ident ? user_ident : dash_str, user_auth ? user_auth : dash_str, Time::FormatHttpd(squid_curtime), - al->_private.method_str, + SQUIDSBUFPRINT(method), al->url, AnyP::ProtocolType_str[al->http.version.protocol], al->http.version.major, al->http.version.minor, diff --git a/src/log/FormatHttpdCommon.cc b/src/log/FormatHttpdCommon.cc index 401d46ec1e..3de36f1e76 100644 --- a/src/log/FormatHttpdCommon.cc +++ b/src/log/FormatHttpdCommon.cc @@ -54,12 +54,18 @@ Log::Format::HttpdCommon(const AccessLogEntry::Pointer &al, Logfile * logfile) char clientip[MAX_IPSTRLEN]; al->getLogClientIp(clientip, MAX_IPSTRLEN); - logfilePrintf(logfile, "%s %s %s [%s] \"%s %s %s/%d.%d\" %d %" PRId64 " %s%s:%s%s", + static SBuf method; + if (al->_private.method_str) + method.assign(al->_private.method_str); + else + method = al->http.method.image(); + + logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " %s %s/%d.%d\" %d %" PRId64 " %s%s:%s%s", clientip, user_ident ? user_ident : dash_str, user_auth ? user_auth : dash_str, Time::FormatHttpd(squid_curtime), - al->_private.method_str, + SQUIDSBUFPRINT(method), al->url, AnyP::ProtocolType_str[al->http.version.protocol], al->http.version.major, al->http.version.minor, diff --git a/src/log/FormatSquidNative.cc b/src/log/FormatSquidNative.cc index 6d154811a5..07a5a99591 100644 --- a/src/log/FormatSquidNative.cc +++ b/src/log/FormatSquidNative.cc @@ -70,7 +70,13 @@ Log::Format::SquidNative(const AccessLogEntry::Pointer &al, Logfile * logfile) char clientip[MAX_IPSTRLEN]; al->getLogClientIp(clientip, MAX_IPSTRLEN); - logfilePrintf(logfile, "%9ld.%03d %6d %s %s%s/%03d %" PRId64 " %s %s %s %s%s/%s %s%s", + static SBuf method; + if (al->_private.method_str) + method.assign(al->_private.method_str); + else + method = al->http.method.image(); + + logfilePrintf(logfile, "%9ld.%03d %6d %s %s%s/%03d %" PRId64 " " SQUIDSBUFPH " %s %s %s%s/%s %s%s", (long int) current_time.tv_sec, (int) current_time.tv_usec / 1000, al->cache.msec, @@ -79,7 +85,7 @@ Log::Format::SquidNative(const AccessLogEntry::Pointer &al, Logfile * logfile) al->http.statusSfx(), al->http.code, al->http.clientReplySz.messageTotal(), - al->_private.method_str, + SQUIDSBUFPRINT(method), al->url, user ? user : dash_str, al->hier.ping.timedout ? "TIMEOUT_" : "", diff --git a/src/log/access_log.cc b/src/log/access_log.cc index b161d7bd8e..4c6853c6e9 100644 --- a/src/log/access_log.cc +++ b/src/log/access_log.cc @@ -109,7 +109,7 @@ accessLogLogTo(CustomLog* log, AccessLogEntry::Pointer &al, ACLChecklist * check else if (al->htcp.opcode) al->_private.method_str = al->htcp.opcode; else - al->_private.method_str = RequestMethodStr(al->http.method); + al->_private.method_str = NULL; if (al->hier.host[0] == '\0') xstrncpy(al->hier.host, dash_str, SQUIDHOSTNAMELEN); diff --git a/src/mgr/ActionParams.cc b/src/mgr/ActionParams.cc index fa71307f24..2b7705e615 100644 --- a/src/mgr/ActionParams.cc +++ b/src/mgr/ActionParams.cc @@ -33,7 +33,7 @@ void Mgr::ActionParams::pack(Ipc::TypedMsgHdr &msg) const { msg.putString(httpUri); - String foo(httpMethod.image()); + String foo(httpMethod.image().toString()); msg.putString(foo); msg.putPod(httpFlags); msg.putString(httpOrigin); diff --git a/src/mk-string-arrays.awk b/src/mk-string-arrays.awk index f199733424..80025d45b6 100644 --- a/src/mk-string-arrays.awk +++ b/src/mk-string-arrays.awk @@ -21,7 +21,7 @@ BEGIN { } # when namespace is encountered store it -/^namespace [a-zA-Z]+/ { +/^namespace *[a-zA-Z]+/ { nspath = tolower($2) "/" # nested folder namespace = $2 # code namespace reconstruct next @@ -33,7 +33,8 @@ codeSkip == 1 { next } /^[ \t]*[A-Z]/ { split($1, t, ",") # remove , - Element[++e] = t[1] + if (sbuf) Element[++e] = "SBuf(\"" t[1] "\")" + else Element[++e] = "\"" t[1] "\"" next } @@ -49,18 +50,20 @@ codeSkip == 1 { next } type = t[1] codeSkip = 1 + if (sbuf) print "#include \"SBuf.h\"" print "#include \"" nspath type ".h\"" # if namesapce is not empty ?? if (namespace) print "namespace " namespace if (namespace) print "{" - print "\nconst char *" type "_str[] = {" + if (sbuf) print "\nconst SBuf " type "_sb[] = {" + else print "\nconst char * " type "_str[] = {" for ( i = 1; i < e; ++i) if (Wrapper[i]) print Wrapper[i] - else print "\t\"" Element[i] "\"," + else print "\t" Element[i] "," - print "\t\"" Element[i] "\"" + print "\t" Element[i] print "};" if (namespace) print "}; // namespace " namespace next diff --git a/src/peer_select.cc b/src/peer_select.cc index 73d68138ee..39a1c93d63 100644 --- a/src/peer_select.cc +++ b/src/peer_select.cc @@ -156,9 +156,9 @@ peerSelect(Comm::ConnectionList * paths, ps_state *psstate; if (entry) - debugs(44, 3, "peerSelect: " << entry->url() ); + debugs(44, 3, *entry << ' ' << entry->url()); else - debugs(44, 3, "peerSelect: " << RequestMethodStr(request->method)); + debugs(44, 3, request->method); psstate = new ps_state; @@ -459,7 +459,7 @@ peerSelectFoo(ps_state * ps) StoreEntry *entry = ps->entry; HttpRequest *request = ps->request; - debugs(44, 3, "peerSelectFoo: '" << RequestMethodStr(request->method) << " " << request->GetHost() << "'"); + debugs(44, 3, request->method << ' ' << request->GetHost()); /** If we don't know whether DIRECT is permitted ... */ if (ps->direct == DIRECT_UNKNOWN) { @@ -703,7 +703,7 @@ peerGetSomeParent(ps_state * ps) CachePeer *p; HttpRequest *request = ps->request; hier_code code = HIER_NONE; - debugs(44, 3, "peerGetSomeParent: " << RequestMethodStr(request->method) << " " << request->GetHost()); + debugs(44, 3, request->method << ' ' << request->GetHost()); if (ps->direct == DIRECT_YES) return; diff --git a/src/store_log.cc b/src/store_log.cc index 5a9856a170..36c27f931c 100644 --- a/src/store_log.cc +++ b/src/store_log.cc @@ -80,7 +80,7 @@ storeLog(int tag, const StoreEntry * e) String ctype=(reply->content_type.size() ? reply->content_type.termedBuf() : str_unknown); logfileLineStart(storelog); - logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d " SQUIDSTRINGPH " %" PRId64 "/%" PRId64 " %s %s\n", + logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d " SQUIDSTRINGPH " %" PRId64 "/%" PRId64 " " SQUIDSBUFPH " %s\n", (int) current_time.tv_sec, (int) current_time.tv_usec / 1000, storeLogTags[tag], @@ -94,7 +94,7 @@ storeLog(int tag, const StoreEntry * e) SQUIDSTRINGPRINT(ctype), reply->content_length, e->contentLen(), - RequestMethodStr(mem->method), + SQUIDSBUFPRINT(mem->method.image()), mem->logUri()); logfileLineEnd(storelog); } else { diff --git a/src/test_cache_digest.cc b/src/test_cache_digest.cc index 4c33607e1e..8613f8b172 100644 --- a/src/test_cache_digest.cc +++ b/src/test_cache_digest.cc @@ -102,18 +102,6 @@ struct _FileIterator { /* globals */ static time_t cur_time = -1; /* timestamp of the current log entry */ -/* copied from url.c */ -const char *RequestMethodStr[] = { - "NONE", - "GET", - "POST", - "PUT", - "HEAD", - "CONNECT", - "TRACE", - "PURGE" -}; - /* copied from url.c */ static HttpRequestMethod methodStrToId(const char *s) diff --git a/src/tests/testHttpRequestMethod.cc b/src/tests/testHttpRequestMethod.cc index bb873b830b..74883302a6 100644 --- a/src/tests/testHttpRequestMethod.cc +++ b/src/tests/testHttpRequestMethod.cc @@ -84,15 +84,15 @@ testHttpRequestMethod::testImage() { // relaxed RFC-compliance parse HTTP methods are upgraded to correct case Config.onoff.relaxed_header_parser = 1; - CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("POST",NULL).image())); - CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("pOsT",NULL).image())); - CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("post",NULL).image())); + CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("POST",NULL).image()); + CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("pOsT",NULL).image()); + CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("post",NULL).image()); // strict RFC-compliance parse HTTP methods are case sensitive Config.onoff.relaxed_header_parser = 0; - CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("POST",NULL).image())); - CPPUNIT_ASSERT_EQUAL(String("pOsT"), String(HttpRequestMethod("pOsT",NULL).image())); - CPPUNIT_ASSERT_EQUAL(String("post"), String(HttpRequestMethod("post",NULL).image())); + CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("POST",NULL).image()); + CPPUNIT_ASSERT_EQUAL(SBuf("pOsT"), HttpRequestMethod("pOsT",NULL).image()); + CPPUNIT_ASSERT_EQUAL(SBuf("post"), HttpRequestMethod("post",NULL).image()); } /* diff --git a/src/tunnel.cc b/src/tunnel.cc index eebe9c5617..e3b534ac46 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -863,7 +863,7 @@ tunnelStart(ClientHttpRequest * http, int64_t * size_ptr, int *status_ptr, const } } - debugs(26, 3, HERE << "'" << RequestMethodStr(request->method) << " " << url << " " << request->http_ver << "'"); + debugs(26, 3, request->method << ' ' << url << ' ' << request->http_ver); ++statCounter.server.all.requests; ++statCounter.server.other.requests; -- 2.47.2