]> git.tdb.fi Git - libs/net.git/blob - source/version.cpp
Pass an exception to signal_socket_error instead of error code
[libs/net.git] / source / version.cpp
1 #include <msp/strings/formatter.h>
2 #include <msp/strings/lexicalcast.h>
3 #include <msp/strings/regex.h>
4 #include "version.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace Http {
10
11 Version parse_version(const std::string &ver)
12 {
13         if(RegMatch match = Regex("^HTTP/([0-9]+).([0-9]+)$").match(ver))
14                 return lexical_cast<unsigned>(match[1].str)<<4 | lexical_cast<unsigned>(match[2].str);
15         else
16                 throw InvalidParameterValue("Invalid HTTP version");
17 }
18
19 string version_str(Version ver)
20 {
21         return format("HTTP/%u.%u", (ver>>4)&0xF, ver&0xF);
22 }
23
24 } // namespace Http
25 } // namespace Msp