Allow empty reason string in validation of HTTP response.
HTTP/1.0 and HTTP/1.1 allow the reason string to be empty. Some servers produce empty reason strings on success, e.g. "HTTP/1.1 200 ", which throws a "bad HTTP response" exception. From the specification: "Reason-Phrase = *<TEXT, excluding CR, LF>" From notational conventions: "*(element) allows any number, including zero" References: www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2 www.w3.org/Protocols/HTTP/1.0/spec.html www.w3.org/Protocols/rfc2616/rfc2616-sec6.html
This commit is contained in:
parent
c87dff7e8f
commit
6334c30eb6
@ -132,15 +132,15 @@ Request::HTTPVersion decodeHTTPVersion(const std::string& v)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void Request::responseStart(const std::string& r)
|
void Request::responseStart(const std::string& r)
|
||||||
{
|
{
|
||||||
const int maxSplit = 2; // HTTP/1.1 nnn reason-string
|
const int maxSplit = 2; // HTTP/1.1 nnn reason-string?
|
||||||
string_list parts = strutils::split(r, NULL, maxSplit);
|
string_list parts = strutils::split(r, NULL, maxSplit);
|
||||||
if (parts.size() != 3) {
|
if (parts.size() < 2) {
|
||||||
throw sg_io_exception("bad HTTP response:" + r);
|
throw sg_io_exception("bad HTTP response:" + r);
|
||||||
}
|
}
|
||||||
|
|
||||||
_responseVersion = decodeHTTPVersion(parts[0]);
|
_responseVersion = decodeHTTPVersion(parts[0]);
|
||||||
_responseStatus = strutils::to_int(parts[1]);
|
_responseStatus = strutils::to_int(parts[1]);
|
||||||
_responseReason = parts[2];
|
_responseReason = parts.size() > 2 ? parts[2] : "";
|
||||||
|
|
||||||
setReadyState(STATUS_RECEIVED);
|
setReadyState(STATUS_RECEIVED);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user