]> git.tdb.fi Git - libs/net.git/blobdiff - source/http/request.cpp
Add a dynamic receiver class for more flexible packet handling
[libs/net.git] / source / http / request.cpp
index f050e0440084d0a0b447875fec014d7ef4940dee..685de332371749d35b7665e7619e399c39726f29 100644 (file)
@@ -1,7 +1,7 @@
+#include "request.h"
 #include <msp/strings/format.h>
 #include <msp/strings/regex.h>
 #include <msp/strings/utils.h>
-#include "request.h"
 #include "utils.h"
 
 using namespace std;
@@ -27,7 +27,9 @@ string Request::str() const
 
 Request Request::parse(const string &str)
 {
-       unsigned lf = str.find('\n');
+       string::size_type lf = str.find('\n');
+       if(lf==0)
+               throw invalid_argument("Request::parse");
        vector<string> parts = split(str.substr(0, lf-(str[lf-1]=='\r')), ' ', 2);
        if(parts.size()<3)
                throw invalid_argument("Request::parse");
@@ -51,11 +53,7 @@ Request Request::from_url(const string &str)
        string path = urlencode(url.path);
        if(path.empty())
                path = "/";
-       if(!url.query.empty())
-       {
-               path += '?';
-               path += url.query;
-       }
+       append(path, "?", url.query);
 
        Request result("GET", path);
        result.set_header("Host", url.host);