@@ -108,23 +108,23 @@ HTTPResponse::HTTPResponse():
108108{
109109}
110110
111-
111+
112112HTTPResponse::HTTPResponse (HTTPStatus status, const std::string& reason):
113113 _status (status),
114114 _reason (reason)
115115{
116116}
117117
118118
119-
119+
120120HTTPResponse::HTTPResponse (const std::string& version, HTTPStatus status, const std::string& reason):
121121 HTTPMessage (version),
122122 _status (status),
123123 _reason (reason)
124124{
125125}
126126
127-
127+
128128HTTPResponse::HTTPResponse (HTTPStatus status):
129129 _status (status),
130130 _reason (getReasonForStatus(status))
@@ -155,8 +155,8 @@ void HTTPResponse::setStatus(const std::string& status)
155155{
156156 setStatus ((HTTPStatus) NumberParser::parse (status));
157157}
158-
159-
158+
159+
160160void HTTPResponse::setReason (const std::string& reason)
161161{
162162 _reason = reason;
@@ -169,7 +169,7 @@ void HTTPResponse::setStatusAndReason(HTTPStatus status, const std::string& reas
169169 _reason = reason;
170170}
171171
172-
172+
173173void HTTPResponse::setStatusAndReason (HTTPStatus status)
174174{
175175 setStatusAndReason (status, getReasonForStatus (status));
@@ -181,7 +181,7 @@ void HTTPResponse::setDate(const Poco::Timestamp& dateTime)
181181 set (DATE, DateTimeFormatter::format (dateTime, DateTimeFormat::HTTP_FORMAT));
182182}
183183
184-
184+
185185Poco::Timestamp HTTPResponse::getDate () const
186186{
187187 const std::string& dateTime = get (DATE);
@@ -240,7 +240,7 @@ void HTTPResponse::read(std::istream& istr)
240240 std::string version;
241241 std::string status;
242242 std::string reason;
243-
243+
244244 int ch = istr.get ();
245245 if (istr.bad ()) throw NetException (" Error reading HTTP response header" );
246246 if (ch == eof) throw NoMessageException ();
@@ -260,9 +260,17 @@ void HTTPResponse::read(std::istream& istr)
260260 HTTPMessage::read (istr);
261261 ch = istr.get ();
262262 while (ch != ' \n ' && ch != eof) { ch = istr.get (); }
263- setVersion (version);
264- setStatus (status);
265- setReason (reason);
263+
264+ try
265+ {
266+ setVersion (version);
267+ setStatus (status);
268+ setReason (reason);
269+ }
270+ catch (SyntaxException & e)
271+ {
272+ throw SyntaxException (e.message (), " , while reading HTTP response: version='" + version + " ', status='" + status + " ', reason='" + reason + " '" );
273+ }
266274}
267275
268276
@@ -282,7 +290,7 @@ const std::string& HTTPResponse::getReasonForStatus(HTTPStatus status)
282290 return HTTP_REASON_CREATED;
283291 case HTTP_ACCEPTED:
284292 return HTTP_REASON_ACCEPTED;
285- case HTTP_NONAUTHORITATIVE:
293+ case HTTP_NONAUTHORITATIVE:
286294 return HTTP_REASON_NONAUTHORITATIVE;
287295 case HTTP_NO_CONTENT:
288296 return HTTP_REASON_NO_CONTENT;
0 commit comments