3 This file is part of libmsphttp
4 Copyright © 2008 Mikkosoft Productions, Mikko Rasa
5 Distributed under the LGPL
8 #include <msp/strings/formatter.h>
9 #include <msp/strings/regex.h>
10 #include <msp/strings/utils.h>
18 Request::Request(const string &m, const string &p):
23 string Request::str() const
25 string result=format("%s %s %s\r\n", method, path, version_str(http_version));
31 Request Request::from_url(const string &url)
33 if(RegMatch match=Regex("^http://([a-zA-Z0-9.-]+)(:([0-9]+))?(/[^ #]*)?$").match(url))
35 string host=match[1].str;
39 string path=match[4].str;
43 Request result("GET", path);
44 result.set_header("host", host);
45 result.set_header("x-port", port);
50 throw InvalidParameterValue("Invalid URL");