X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fhttp%2Frequest.cpp;h=685de332371749d35b7665e7619e399c39726f29;hb=HEAD;hp=01948592ef9c8033119bf86bfbf1ff40c66307f7;hpb=aea563e0c847ab07f60adc92b40a9f046738932c;p=libs%2Fnet.git diff --git a/source/http/request.cpp b/source/http/request.cpp index 0194859..685de33 100644 --- a/source/http/request.cpp +++ b/source/http/request.cpp @@ -1,7 +1,7 @@ +#include "request.h" #include #include #include -#include "request.h" #include "utils.h" using namespace std; @@ -12,7 +12,10 @@ namespace Http { Request::Request(const string &m, const string &p): method(m), path(p) -{ } +{ + if(path.find(' ')!=string::npos) + throw invalid_argument("Request::Request"); +} string Request::str() const { @@ -24,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 parts = split(str.substr(0, lf-(str[lf-1]=='\r')), ' ', 2); if(parts.size()<3) throw invalid_argument("Request::parse"); @@ -45,14 +50,10 @@ Request Request::from_url(const string &str) if(url.scheme!="http") throw invalid_argument("Request::from_url"); - string path = url.path; + 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);