22 #ifndef ALICEO2_HTTPPARSER_H 23 #define ALICEO2_HTTPPARSER_H 32 std::string protocol, user, password, host, path, search,
url;
37 static inline std::string TailSlice(std::string& subject, std::string delimiter,
bool keep_delim =
false)
41 auto delimiter_location = subject.find(delimiter);
42 auto delimiter_length = delimiter.length();
43 std::string output =
"";
45 if (delimiter_location < std::string::npos) {
46 auto start = keep_delim ? delimiter_location : delimiter_location + delimiter_length;
47 auto end = subject.length() - start;
48 output = subject.substr(start, end);
49 subject = subject.substr(0, delimiter_location);
54 static inline std::string HeadSlice(std::string& subject, std::string delimiter)
58 auto delimiter_location = subject.find(delimiter);
59 auto delimiter_length = delimiter.length();
60 std::string output =
"";
61 if (delimiter_location < std::string::npos) {
62 output = subject.substr(0, delimiter_location);
63 subject = subject.substr(delimiter_location + delimiter_length, subject.length() - (delimiter_location + delimiter_length));
69 static inline int ExtractPort(std::string& hostport)
72 std::string portstring = TailSlice(hostport,
":");
74 port = atoi(portstring.c_str());
75 }
catch (std::exception& e) {
81 static inline std::string ExtractPath(std::string& in) {
return TailSlice(in,
"/",
true); }
82 static inline std::string ExtractProtocol(std::string& in) {
return HeadSlice(in,
"://"); }
83 static inline std::string ExtractSearch(std::string& in) {
return TailSlice(in,
"?"); }
84 static inline std::string ExtractPassword(std::string& userpass) {
return TailSlice(userpass,
":"); }
85 static inline std::string ExtractUserpass(std::string& in) {
return HeadSlice(in,
"@"); }
88 static inline url ParseHttpUrl(std::string& in)
93 ret.protocol = ExtractProtocol(in);
94 ret.search = ExtractSearch(in);
95 ret.path = ExtractPath(in);
96 std::string userpass = ExtractUserpass(in);
97 ret.password = ExtractPassword(userpass);
99 ret.port = ExtractPort(in);
Definition: UriParser.h:29
Definition: UriParser.h:31