]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/http/StatusLine.cc
d975350dbdda2b6e261bf2d3b17565f42c130778
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 57 HTTP Status-line */
12 #include "base/Packable.h"
14 #include "http/StatusLine.h"
17 Http::StatusLine::init()
19 set(Http::ProtocolVersion(), Http::scNone
, NULL
);
23 Http::StatusLine::clean()
25 set(Http::ProtocolVersion(), Http::scInternalServerError
, NULL
);
30 Http::StatusLine::set(const AnyP::ProtocolVersion
&newVersion
, const Http::StatusCode newStatus
, const char *newReason
)
32 protocol
= AnyP::PROTO_HTTP
;
35 /* Note: no xstrdup for 'reason', assumes constant 'reasons' */
40 Http::StatusLine::reason() const
42 return reason_
? reason_
: Http::StatusCodeString(status());
46 Http::StatusLine::packInto(Packable
* p
) const
51 /* AYJ: see bug 2469 - RFC2616 confirms stating 'SP characters' plural! */
52 static const char *Http1StatusLineFormat
= "HTTP/%d.%d %3d %s\r\n";
53 static const char *IcyStatusLineFormat
= "ICY %3d %s\r\n";
55 /* handle ICY protocol status line specially. Pass on the bad format. */
56 if (protocol
== AnyP::PROTO_ICY
) {
57 debugs(57, 9, "packing sline " << this << " using " << p
<< ":");
58 debugs(57, 9, "FORMAT=" << IcyStatusLineFormat
);
59 debugs(57, 9, "ICY " << status() << " " << reason());
60 p
->appendf(IcyStatusLineFormat
, status(), reason());
64 debugs(57, 9, "packing sline " << this << " using " << p
<< ":");
65 debugs(57, 9, "FORMAT=" << Http1StatusLineFormat
);
66 debugs(57, 9, "HTTP/" << version
.major
<< "." << version
.minor
<< " " << status() << " " << reason());
67 p
->appendf(Http1StatusLineFormat
, version
.major
, version
.minor
, status(), reason());
71 * Parse character string.
72 * XXX: Note 'end' currently unused, so NULL-termination assumed.
75 Http::StatusLine::parse(const String
&protoPrefix
, const char *start
, const char * /*end*/)
77 status_
= Http::scInvalidHeader
; /* Squid header parsing error */
79 // XXX: HttpMsg::parse() has a similar check but is using
80 // casesensitive comparison (which is required by HTTP errata?)
82 if (protoPrefix
.cmp("ICY", 3) == 0) {
83 debugs(57, 3, "Invalid HTTP identifier. Detected ICY protocol istead.");
84 protocol
= AnyP::PROTO_ICY
;
85 start
+= protoPrefix
.size();
86 } else if (protoPrefix
.caseCmp(start
, protoPrefix
.size()) == 0) {
88 start
+= protoPrefix
.size();
90 if (!xisdigit(*start
))
93 // XXX: HTTPbis have defined this to be single-digit version numbers. no need to sscanf()
94 // XXX: furthermore, only HTTP/1 will be using ASCII format digits
96 if (sscanf(start
, "%d.%d", &version
.major
, &version
.minor
) != 2) {
97 debugs(57, 7, "Invalid HTTP identifier.");
103 if (!(start
= strchr(start
, ' ')))
106 // XXX: should we be using xstrtoui() or xatoui() ?
107 status_
= static_cast<Http::StatusCode
>(atoi(++start
));
109 // XXX check if the given 'reason' is the default status string, if not save to reason_
111 /* we ignore 'reason-phrase' */
112 /* Should assert start < end ? */
113 return true; /* success */