]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Update Http::ProtocolVersion() to initializer functions
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 11 Dec 2014 08:35:32 +0000 (00:35 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 11 Dec 2014 08:35:32 +0000 (00:35 -0800)
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.

13 files changed:
src/AccessLogEntry.h
src/HttpMsg.cc
src/HttpMsg.h
src/HttpReply.cc
src/client_side_reply.cc
src/client_side_request.cc
src/ftp/Elements.cc
src/http.cc
src/http/ProtocolVersion.h
src/http/StatusLine.cc
src/http/StatusLine.h
src/icmp/net_db.cc
src/servers/HttpServer.cc

index 6aef0eac014c8bd5684feb98b91967e3873b907f..cf939a5f1a84dcae6f412f064d9e1c0e11ff7e38 100644 (file)
@@ -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)
 
index 3b59974db9011fb66632c5a1e9977e8650740738..99894f1fb3756cea738d8f72f254306b0abc2ef3 100644 (file)
@@ -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.
index a67b01627bdbb58a960483bfa0558e4a3a3dbaf2..1e222d9978dabba15cd58e8db9e7b710042a928b 100644 (file)
@@ -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;
 
index 49c4dcb39b221cc61eec1cf90277c4534f323646..7552d1f9a0de972893f258f5d7f65abace55d92a 100644 (file)
@@ -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;
 }
 
index edf835487a53219f8ea1ce0ad8cf4ed45162c229..c81b4d5bde2b7927f6dc4b1953ec9fd9ac8c8e87 100644 (file)
@@ -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 */
index f5ad527d485f4d48dfb3b712077f68ed8d6be318..f9f6801a982383f353907a9544328e950a9cc519 100644 (file)
@@ -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);
index c9e70c217eae60a72d4f0cda180e4c3a13bf6b7a..653b745dc4313c0925664a4925ab7ad30f71fa1a 100644 (file)
@@ -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);
 
index f776d9e5659206840590341a2a4f48d95dc7d636..ea319aca20c53e07e00829f0a382acf56f1f8001 100644 (file)
@@ -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);
index e5f486f140643ad86379b0e14e34060faebf0f30..8d4cda37f737aa32a63683671f6cce7ed5913906 100644 (file)
 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
 
index 63302adbb3e4e3b9e02e3f035dd7bc840f9ce65a..ff0a77e95357b7e79380b7ec1193c4e7c6f5b564 100644 (file)
@@ -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;
index 890a6fc4d6f04a259654d06bbe4b6f8e7df4f48f..a464aebab90b967713820b152d3306260ebe4f41 100644 (file)
@@ -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
index b87d51a5d274633aa0ee7cc6b9e2becd809fc01a..19ed0d057d5cd09cd24d12def2004f95f3cb608c 100644 (file)
@@ -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;
index a0d70aa3b1a1c47c53d591b44e8287511e6a0b2c..e1340455e3b95fc0af8a96edfd50f7dd2783e71d 100644 (file)
@@ -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<Http::Server, ClientSocketContext::Pointer> CbDialer;
             const AsyncCall::Pointer cb = asyncCall(11, 3,  "Http::Server::proceedAfterBodyContinuation", CbDialer(this, &Http::Server::proceedAfterBodyContinuation, ClientSocketContext::Pointer(context)));