]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Removed redundant Http::StatusLine::protocol (#794)
authorAlex Rousskov <rousskov@measurement-factory.com>
Sat, 3 Apr 2021 03:04:42 +0000 (03:04 +0000)
committerAmos Jeffries <yadij@users.noreply.github.com>
Thu, 6 May 2021 04:56:26 +0000 (16:56 +1200)
Also polished Http::StatusLine initialization, but that part needs a
lot more work to get rid of Http::StatusLine::init().

src/client_side_reply.cc
src/http.cc
src/http/StatusLine.cc
src/http/StatusLine.h

index 424e887169aa9a78e6713e003b1c529171c81693..c0053eebdeec6f9621820338a16f12f9ca02a90a 100644 (file)
@@ -1574,7 +1574,7 @@ clientReplyContext::buildReplyHeader()
 #endif
 
     const bool maySendChunkedReply = !request->multipartRangeRequest() &&
-                                     reply->sline.protocol == AnyP::PROTO_HTTP && // response is HTTP
+                                     reply->sline.version.protocol == AnyP::PROTO_HTTP && // response is HTTP
                                      (request->http_ver >= Http::ProtocolVersion(1,1));
 
     /* Check whether we should send keep-alive */
@@ -1658,7 +1658,7 @@ clientReplyContext::cloneReply()
 
     http->al->reply = reply;
 
-    if (reply->sline.protocol == AnyP::PROTO_HTTP) {
+    if (reply->sline.version.protocol == AnyP::PROTO_HTTP) {
         /* RFC 2616 requires us to advertise our version (but only on real HTTP traffic) */
         reply->sline.version = Http::ProtocolVersion();
     }
index 693666a52ae85786097c6b647ca22f7c7c6ed518..2fb12df6a248dc53a1409ccf3ab12875c24ff38e 100644 (file)
@@ -730,18 +730,11 @@ HttpStateData::processReplyHeader()
     // XXX: RFC 7230 indicates we MAY ignore the reason phrase,
     //      and use an empty string on unknown status.
     //      We do that now to avoid performance regression from using SBuf::c_str()
-    newrep->sline.set(Http::ProtocolVersion(1,1), hp->messageStatus() /* , hp->reasonPhrase() */);
-    newrep->sline.protocol = newrep->sline.version.protocol = hp->messageProtocol().protocol;
-    newrep->sline.version.major = hp->messageProtocol().major;
-    newrep->sline.version.minor = hp->messageProtocol().minor;
+    newrep->sline.set(hp->messageProtocol(), hp->messageStatus() /* , hp->reasonPhrase() */);
 
     // parse headers
     if (!newrep->parseHeader(*hp)) {
-        // XXX: when Http::ProtocolVersion is a function, remove this hack. just set with messageProtocol()
-        newrep->sline.set(Http::ProtocolVersion(), Http::scInvalidHeader);
-        newrep->sline.version.protocol = hp->messageProtocol().protocol;
-        newrep->sline.version.major = hp->messageProtocol().major;
-        newrep->sline.version.minor = hp->messageProtocol().minor;
+        newrep->sline.set(hp->messageProtocol(), Http::scInvalidHeader);
         debugs(11, 2, "error parsing response headers mime block");
     }
 
@@ -752,14 +745,14 @@ HttpStateData::processReplyHeader()
 
     newrep->removeStaleWarnings();
 
-    if (newrep->sline.protocol == AnyP::PROTO_HTTP && Http::Is1xx(newrep->sline.status())) {
+    if (newrep->sline.version.protocol == AnyP::PROTO_HTTP && Http::Is1xx(newrep->sline.status())) {
         handle1xx(newrep);
         ctx_exit(ctx);
         return;
     }
 
     flags.chunked = false;
-    if (newrep->sline.protocol == AnyP::PROTO_HTTP && newrep->header.chunked()) {
+    if (newrep->sline.version.protocol == AnyP::PROTO_HTTP && newrep->header.chunked()) {
         flags.chunked = true;
         httpChunkDecoder = new Http1::TeChunkedParser;
     }
index cfacf9a6d1c1c13fefa77e773cce55274f6a48f6..233850a30fd8703dcd4165056711c6880788ab84 100644 (file)
@@ -34,7 +34,6 @@ Http::StatusLine::clean()
 void
 Http::StatusLine::set(const AnyP::ProtocolVersion &newVersion, const Http::StatusCode newStatus, const char *newReason)
 {
-    protocol = AnyP::PROTO_HTTP;
     version = newVersion;
     status_ = newStatus;
     /* Note: no xstrdup for 'reason', assumes constant 'reasons' */
@@ -69,7 +68,7 @@ Http::StatusLine::packInto(Packable * p) const
     static const char *IcyStatusLineFormat = "ICY %3d %s\r\n";
 
     /* handle ICY protocol status line specially. Pass on the bad format. */
-    if (protocol == AnyP::PROTO_ICY) {
+    if (version.protocol == AnyP::PROTO_ICY) {
         debugs(57, 9, "packing sline " << this << " using " << p << ":");
         debugs(57, 9, "FORMAT=" << IcyStatusLineFormat );
         debugs(57, 9, "ICY " << packedStatus << " " << packedReason);
@@ -93,7 +92,7 @@ Http::StatusLine::parse(const String &protoPrefix, const char *start, const char
 
     if (protoPrefix.cmp("ICY", 3) == 0) {
         debugs(57, 3, "Invalid HTTP identifier. Detected ICY protocol instead.");
-        protocol = AnyP::PROTO_ICY;
+        version = AnyP::ProtocolVersion(AnyP::PROTO_ICY, 1, 0);
         start += protoPrefix.size();
     } else if (protoPrefix.caseCmp(start, protoPrefix.size()) == 0) {
 
index a0a9d6b45600254f819d2a73cf46e20279f735cd..03817826d818c6b8c2b3eda7602d7163f89c2ecd 100644 (file)
@@ -20,7 +20,7 @@ namespace Http
 {
 
 /**
- * Holds the values parsed from an HTTP reply status line.
+ * Holds the values parsed from an HTTP-like reply status line.
  *
  * For example: HTTP/1.1 200 OK
  */
@@ -59,22 +59,14 @@ public:
 public:
     /* public, read only */
 
-    /**
-     * By rights protocol name should be a constant "HTTP", with no need for this field to exist.
-     * 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 AnyP::ProtocolVersion. We should be able to use version.protocol instead now.
-    AnyP::ProtocolType protocol;
-
     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
-    Http::StatusCode status_;
+    Http::StatusCode status_ = scNone;
 
     /// points to a _constant_ string (default or supplied), never free()d
-    const char *reason_;
+    const char *reason_ = nullptr;
 };
 
 } // namespace Http