--- /dev/null
+/* $Id$
+
+This file is part of libmsphttp
+Copyright © 2008 Mikkosoft Productions, Mikko Rasa
+Distributed under the LGPL
+*/
+
+#include <msp/strings/formatter.h>
+#include <msp/strings/regex.h>
+#include <msp/strings/utils.h>
+#include "request.h"
+
+using namespace std;
+
+namespace Msp {
+namespace Http {
+
+Request::Request(const string &m, const string &p):
+ method(m),
+ path(p)
+{ }
+
+string Request::str() const
+{
+ string result=format("%s %s %s\r\n", method, path, version_str(http_version));
+ result+=str_common();
+
+ return result;
+}
+
+Request Request::from_url(const string &url)
+{
+ if(RegMatch match=Regex("^http://([a-zA-Z0-9.-]+)(:([0-9]+))?(/[^ #]*)?$").match(url))
+ {
+ string host=match[1].str;
+ string port="80";
+ if(match[3])
+ port=match[3].str;
+ string path=match[4].str;
+ if(path.empty())
+ path="/";
+
+ Request result("GET", path);
+ result.set_header("host", host);
+ result.set_header("x-port", port);
+
+ return result;
+ }
+ else
+ throw InvalidParameterValue("Invalid URL");
+}
+
+} // namespace Http
+} // namespace Msp