From: Amos Jeffries Date: Thu, 11 Dec 2014 08:35:32 +0000 (-0800) Subject: Update Http::ProtocolVersion() to initializer functions X-Git-Tag: merge-candidate-3-v1~440 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2592bc708595793aa1635c21e80f4f9712000e76;p=thirdparty%2Fsquid.git Update Http::ProtocolVersion() to initializer functions The Http::ProtocolVersion(*) does not work sufficiently well as a class hierarchy. Convert Http::ProtocolVersion to two functions: * Http::ProtocolVersion() providing the default Squid HTTP version level, and * Http::ProtocolVersion(unsigned, unsigned) providing the HTTP version details for the given level. NP: using two overloaded functions instead of one with default parameter values because with HTTP/0.x and HTTP/2.x we cannot safely default just the minor value. ie. using two functions prevents mistakenly using HTTP/2.1, HTTP/0.1 or HTTP/1.0 if the second parameter is omitted. All variables must now be of type AnyP::ProtocolVersion, and should be constructed from an appropriate Foo::ProtocolVersion() function. --- diff --git a/src/AccessLogEntry.h b/src/AccessLogEntry.h index 6aef0eac01..cf939a5f1a 100644 --- a/src/AccessLogEntry.h +++ b/src/AccessLogEntry.h @@ -72,7 +72,7 @@ public: HttpRequestMethod method; int code; const char *content_type; - Http::ProtocolVersion version; + AnyP::ProtocolVersion version; bool timedout; ///< terminated due to a lifetime or I/O timeout bool aborted; ///< other abnormal termination (e.g., I/O error) diff --git a/src/HttpMsg.cc b/src/HttpMsg.cc index 3b59974db9..99894f1fb3 100644 --- a/src/HttpMsg.cc +++ b/src/HttpMsg.cc @@ -300,7 +300,7 @@ HttpMsg::setContentLength(int64_t clen) bool HttpMsg::persistent() const { - if (http_ver > Http::ProtocolVersion(1, 0)) { + if (http_ver > Http::ProtocolVersion(1,0)) { /* * for modern versions of HTTP: persistent unless there is * a "Connection: close" header. diff --git a/src/HttpMsg.h b/src/HttpMsg.h index a67b01627b..1e222d9978 100644 --- a/src/HttpMsg.h +++ b/src/HttpMsg.h @@ -47,7 +47,7 @@ public: public: /// HTTP-Version field in the first line of the message. /// see RFC 7230 section 3.1 - Http::ProtocolVersion http_ver; + AnyP::ProtocolVersion http_ver; HttpHeader header; diff --git a/src/HttpReply.cc b/src/HttpReply.cc index 49c4dcb39b..7552d1f9a0 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -153,7 +153,7 @@ HttpReply::make304() const /* rv->cache_control */ /* rv->content_range */ /* rv->keep_alive */ - rv->sline.set(Http::ProtocolVersion(1,1), Http::scNotModified, NULL); + rv->sline.set(Http::ProtocolVersion(), Http::scNotModified, NULL); for (t = 0; ImsEntries[t] != HDR_OTHER; ++t) if ((e = header.findEntry(ImsEntries[t]))) @@ -180,7 +180,7 @@ HttpReply::setHeaders(Http::StatusCode status, const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expiresTime) { HttpHeader *hdr; - sline.set(Http::ProtocolVersion(1,1), status, reason); + sline.set(Http::ProtocolVersion(), status, reason); hdr = &header; hdr->putStr(HDR_SERVER, visible_appname_string); hdr->putStr(HDR_MIME_VERSION, "1.0"); @@ -214,7 +214,7 @@ void HttpReply::redirect(Http::StatusCode status, const char *loc) { HttpHeader *hdr; - sline.set(Http::ProtocolVersion(1,1), status, NULL); + sline.set(Http::ProtocolVersion(), status, NULL); hdr = &header; hdr->putStr(HDR_SERVER, APP_FULLNAME); hdr->putTime(HDR_DATE, squid_curtime); @@ -477,7 +477,7 @@ HttpReply::httpMsgParseError() { int result(HttpMsg::httpMsgParseError()); /* indicate an error in the status line */ - sline.set(Http::ProtocolVersion(1,1), Http::scInvalidHeader); + sline.set(Http::ProtocolVersion(), Http::scInvalidHeader); return result; } diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index edf835487a..c81b4d5bde 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -1469,7 +1469,7 @@ clientReplyContext::buildReplyHeader() const bool maySendChunkedReply = !request->multipartRangeRequest() && reply->sline.protocol == AnyP::PROTO_HTTP && // response is HTTP - (request->http_ver >= Http::ProtocolVersion(1, 1)); + (request->http_ver >= Http::ProtocolVersion(1,1)); /* Check whether we should send keep-alive */ if (!Config.onoff.error_pconns && reply->sline.status() >= 400 && !request->flags.mustKeepalive) { @@ -1561,8 +1561,8 @@ clientReplyContext::cloneReply() HTTPMSGLOCK(reply); if (reply->sline.protocol == AnyP::PROTO_HTTP) { - /* RFC 2616 requires us to advertise our 1.1 version (but only on real HTTP traffic) */ - reply->sline.version = Http::ProtocolVersion(1,1); + /* RFC 2616 requires us to advertise our version (but only on real HTTP traffic) */ + reply->sline.version = Http::ProtocolVersion(); } /* do header conversions */ diff --git a/src/client_side_request.cc b/src/client_side_request.cc index f5ad527d48..f9f6801a98 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -366,8 +366,7 @@ clientBeginRequest(const HttpRequestMethod& method, char const *url, CSCB * stre request->my_addr.port(0); - /* Our version is HTTP/1.1 */ - request->http_ver = Http::ProtocolVersion(1,1); + request->http_ver = Http::ProtocolVersion(); http->request = request; HTTPMSGLOCK(http->request); diff --git a/src/ftp/Elements.cc b/src/ftp/Elements.cc index c9e70c217e..653b745dc4 100644 --- a/src/ftp/Elements.cc +++ b/src/ftp/Elements.cc @@ -31,7 +31,7 @@ Ftp::HttpReplyWrapper(const int ftpStatus, const char *ftpReason, const Http::St { HttpReply *const reply = new HttpReply; - Http::ProtocolVersion httpVersion = Http::ProtocolVersion( + AnyP::ProtocolVersion httpVersion = Http::ProtocolVersion( Ftp::ProtocolVersion().major, Ftp::ProtocolVersion().minor); reply->sline.set(httpVersion, httpStatus); diff --git a/src/http.cc b/src/http.cc index f776d9e565..ea319aca20 100644 --- a/src/http.cc +++ b/src/http.cc @@ -722,7 +722,7 @@ HttpStateData::processReplyHeader() flags.headers_parsed = true; // XXX: when sanityCheck is gone and Http::StatusLine is used to parse, // the sline should be already set the appropriate values during that parser stage - newrep->sline.set(Http::ProtocolVersion(1,1), error); + newrep->sline.set(Http::ProtocolVersion(), error); HttpReply *vrep = setVirginReply(newrep); entry->replaceHttpReply(vrep); ctx_exit(ctx); @@ -1261,7 +1261,7 @@ HttpStateData::continueAfterParsingHeader() // check for header parsing errors if (HttpReply *vrep = virginReply()) { const Http::StatusCode s = vrep->sline.status(); - const Http::ProtocolVersion &v = vrep->sline.version; + const AnyP::ProtocolVersion &v = vrep->sline.version; if (s == Http::scInvalidHeader && v != Http::ProtocolVersion(0,9)) { debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: Bad header encountered from " << entry->url() << " AKA " << request->GetHost() << request->urlpath.termedBuf() ); error = ERR_INVALID_RESP; @@ -2082,13 +2082,13 @@ mb_size_t HttpStateData::buildRequestPrefix(MemBuf * mb) { const int offset = mb->size; - /* Uses a local httpver variable to print the HTTP/1.1 label + /* Uses a local httpver variable to print the HTTP label * since the HttpRequest may have an older version label. * XXX: This could create protocol bugs as the headers sent and * flow control should all be based on the HttpRequest version * not the one we are sending. Needs checking. */ - Http::ProtocolVersion httpver(1,1); + const AnyP::ProtocolVersion httpver = Http::ProtocolVersion(); const char * url; if (_peer && !_peer->options.originserver) url = urlCanonical(request); diff --git a/src/http/ProtocolVersion.h b/src/http/ProtocolVersion.h index e5f486f140..8d4cda37f7 100644 --- a/src/http/ProtocolVersion.h +++ b/src/http/ProtocolVersion.h @@ -14,20 +14,25 @@ namespace Http { +/// HTTP version label information +inline AnyP::ProtocolVersion +ProtocolVersion(unsigned int aMajor, unsigned int aMinor) +{ + return AnyP::ProtocolVersion(AnyP::PROTO_HTTP,aMajor,aMinor); +} + /** - * Stores HTTP version label information. + * HTTP version label information. * - * Squid being conditionally compliant with RFC 2616 + * Squid being conditionally compliant with RFC 7230 * on both client and server connections the default * value is HTTP/1.1. */ -class ProtocolVersion : public AnyP::ProtocolVersion +inline AnyP::ProtocolVersion +ProtocolVersion() { -public: - ProtocolVersion() : AnyP::ProtocolVersion(AnyP::PROTO_HTTP,1,1) {} - - ProtocolVersion(unsigned int aMajor, unsigned int aMinor) : AnyP::ProtocolVersion(AnyP::PROTO_HTTP,aMajor,aMinor) {} -}; + return AnyP::ProtocolVersion(AnyP::PROTO_HTTP,1,1); +} }; // namespace Http diff --git a/src/http/StatusLine.cc b/src/http/StatusLine.cc index 63302adbb3..ff0a77e953 100644 --- a/src/http/StatusLine.cc +++ b/src/http/StatusLine.cc @@ -27,7 +27,7 @@ Http::StatusLine::clean() /* set values */ void -Http::StatusLine::set(const Http::ProtocolVersion &newVersion, const Http::StatusCode newStatus, const char *newReason) +Http::StatusLine::set(const AnyP::ProtocolVersion &newVersion, const Http::StatusCode newStatus, const char *newReason) { protocol = AnyP::PROTO_HTTP; version = newVersion; diff --git a/src/http/StatusLine.h b/src/http/StatusLine.h index 890a6fc4d6..a464aebab9 100644 --- a/src/http/StatusLine.h +++ b/src/http/StatusLine.h @@ -35,7 +35,7 @@ public: /// set this status-line to the given values /// when reason is NULL the default message text for this StatusCode will be used - void set(const Http::ProtocolVersion &newVersion, Http::StatusCode newStatus, const char *newReason = NULL); + void set(const AnyP::ProtocolVersion &newVersion, Http::StatusCode newStatus, const char *newReason = NULL); /// retrieve the status code for this status line Http::StatusCode status() const { return status_; } @@ -60,10 +60,10 @@ public: * However there are protocols which violate HTTP by sending their own custom formats * back with other protocol names (ICY streaming format being the current major problem). */ - // XXX: protocol is part of Http::ProtocolVersion. We should be able to use version.protocol instead now. + // XXX: protocol is part of AnyP::ProtocolVersion. We should be able to use version.protocol instead now. AnyP::ProtocolType protocol; - Http::ProtocolVersion version; ///< breakdown of protocol version label: (HTTP/ICY) and (0.9/1.0/1.1) + AnyP::ProtocolVersion version; ///< breakdown of protocol version label: (HTTP/ICY) and (0.9/1.0/1.1) private: /// status code. ie 100 ... 200 ... 404 ... 599 diff --git a/src/icmp/net_db.cc b/src/icmp/net_db.cc index b87d51a5d2..19ed0d057d 100644 --- a/src/icmp/net_db.cc +++ b/src/icmp/net_db.cc @@ -1293,7 +1293,7 @@ netdbExchangeStart(void *data) HTTPMSGLOCK(ex->r); assert(NULL != ex->r); - ex->r->http_ver = Http::ProtocolVersion(1,1); + ex->r->http_ver = Http::ProtocolVersion(); ex->connstate = STATE_HEADER; ex->e = storeCreateEntry(uri, uri, RequestFlags(), Http::METHOD_GET); ex->buf_sz = NETDB_REQBUF_SZ; diff --git a/src/servers/HttpServer.cc b/src/servers/HttpServer.cc index a0d70aa3b1..e1340455e3 100644 --- a/src/servers/HttpServer.cc +++ b/src/servers/HttpServer.cc @@ -257,7 +257,7 @@ Http::Server::processParsedRequest(ClientSocketContext *context) request->forcedBodyContinuation = true; //sendControlMsg HttpReply::Pointer rep = new HttpReply; - rep->sline.set(Http::ProtocolVersion(1,1), Http::scContinue); + rep->sline.set(Http::ProtocolVersion(), Http::scContinue); typedef UnaryMemFunT CbDialer; const AsyncCall::Pointer cb = asyncCall(11, 3, "Http::Server::proceedAfterBodyContinuation", CbDialer(this, &Http::Server::proceedAfterBodyContinuation, ClientSocketContext::Pointer(context)));