#include <msp/strings/regex.h>
#include <msp/strings/utils.h>
#include "request.h"
+#include "utils.h"
using namespace std;
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