]> git.mxchange.org Git - simgear.git/commitdiff
HTTP: tweak response parsing.
authorJames Turner <zakalawe@mac.com>
Tue, 7 Jan 2014 16:22:10 +0000 (16:22 +0000)
committerJames Turner <zakalawe@mac.com>
Tue, 7 Jan 2014 16:22:10 +0000 (16:22 +0000)
Signal a parse failure via an exception, instead of via a status
code, since this is hard to disambiguate from a valid server-side
status code.

simgear/io/HTTPClient.cxx
simgear/io/HTTPRequest.cxx

index ecc63f844054154a5a99230658848f2d46da05fb..e345c093d66cbd4467e052a86b84dbe363a008e0 100644 (file)
@@ -65,12 +65,6 @@ class Connection;
 typedef std::multimap<std::string, Connection*> ConnectionDict;
 typedef std::list<Request_ptr> RequestList;
 
-static bool isFailureStatus(int httpStatus)
-{
-  int majorCode = httpStatus / 100;
-  return (majorCode != 2);
-}
-
 class Client::ClientPrivate
 {
 public:
@@ -220,12 +214,12 @@ public:
         assert(state == STATE_WAITING_FOR_RESPONSE);
         
         activeRequest = sentRequests.front();
-       activeRequest->responseStart(buffer);
-       if (isFailureStatus(activeRequest->responseCode())) {
-         handleError(EIO);
-         return;
-       }
-      
+        try {
+            activeRequest->responseStart(buffer);
+        } catch (sg_exception& e) {
+            handleError(EIO);
+        }
+        
       state = STATE_GETTING_HEADERS;
       buffer.clear();
       if (activeRequest->responseCode() == 204) {
index d51d97902ef3d47a61bb9a9f175bb546bd495b73..46c64d5df84654c3698df0f72b59fab81ecd2de0 100644 (file)
@@ -4,6 +4,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/misc/strutils.hxx>
 #include <simgear/props/props_io.hxx>
+#include <simgear/structure/exception.hxx>
 
 namespace simgear
 {
@@ -115,8 +116,7 @@ void Request::responseStart(const std::string& r)
     const int maxSplit = 2; // HTTP/1.1 nnn reason-string
     string_list parts = strutils::split(r, NULL, maxSplit);
     if (parts.size() != 3) {
-        setFailure(400, "malformed HTTP response header");
-        return;
+        throw sg_io_exception("bad HTTP response");
     }
     
     _responseVersion = decodeHTTPVersion(parts[0]);