X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frequest.cpp;fp=source%2Frequest.cpp;h=6bad3700681fefdffd40178a88e44cb146442e0b;hb=f53eda26a3160972908f15c2427a60b0b82fbe87;hp=bcf36c991f727f5c539a6431304d68691dd5be92;hpb=077408f98f08fac1a098a501fffdb22728a57a46;p=libs%2Fnet.git diff --git a/source/request.cpp b/source/request.cpp index bcf36c9..6bad370 100644 --- a/source/request.cpp +++ b/source/request.cpp @@ -9,6 +9,7 @@ Distributed under the LGPL #include #include #include "request.h" +#include "utils.h" using namespace std; @@ -45,23 +46,25 @@ Request Request::parse(const string &str) return result; } -Request Request::from_url(const string &url) +Request Request::from_url(const string &str) { - if(RegMatch match=Regex("^http://([a-zA-Z0-9.-]+(:[0-9]+)?)(/[^ #]*)?$").match(url)) + Url url=parse_url(str); + if(url.scheme!="http") + throw InvalidParameterValue("Only http scheme is supported"); + string path=url.path; + if(path.empty()) + path="/"; + if(!url.query.empty()) { - string host=match[1].str; - string path=match[3].str; - if(path.empty()) - path="/"; + path+='?'; + path+=url.query; + } - Request result("GET", path); - result.set_header("Host", host); - result.set_header("Connection", "close"); + Request result("GET", path); + result.set_header("Host", url.host); + result.set_header("Connection", "close"); - return result; - } - else - throw InvalidParameterValue("Invalid URL"); + return result; } } // namespace Http