From 6334c30eb6ea22c514dd39d0993ea489dd9abbcf Mon Sep 17 00:00:00 2001 From: Richard Senior Date: Wed, 1 Feb 2017 09:20:01 +0000 Subject: [PATCH] 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 = *" 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 --- simgear/io/HTTPRequest.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simgear/io/HTTPRequest.cxx b/simgear/io/HTTPRequest.cxx index 6b06785a..5e5de889 100644 --- a/simgear/io/HTTPRequest.cxx +++ b/simgear/io/HTTPRequest.cxx @@ -132,15 +132,15 @@ Request::HTTPVersion decodeHTTPVersion(const std::string& v) //------------------------------------------------------------------------------ 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); - if (parts.size() != 3) { + if (parts.size() < 2) { throw sg_io_exception("bad HTTP response:" + r); } _responseVersion = decodeHTTPVersion(parts[0]); _responseStatus = strutils::to_int(parts[1]); - _responseReason = parts[2]; + _responseReason = parts.size() > 2 ? parts[2] : ""; setReadyState(STATUS_RECEIVED); }