diff --git a/include/fc/filesystem.hpp b/include/fc/filesystem.hpp index fbd5276..780f7a9 100644 --- a/include/fc/filesystem.hpp +++ b/include/fc/filesystem.hpp @@ -1,5 +1,4 @@ -#ifndef _FC_FILESYSTEM_HPP_ -#define _FC_FILESYSTEM_HPP_ +#pragma once #include #include @@ -72,4 +71,3 @@ namespace fc { path temp_directory_path(); } -#endif // _FC_FILESYSTEM_HPP_ diff --git a/include/fc/http/connection.hpp b/include/fc/http/connection.hpp index 41e94e5..0f71530 100644 --- a/include/fc/http/connection.hpp +++ b/include/fc/http/connection.hpp @@ -32,6 +32,7 @@ namespace fc { }; struct request { + fc::string get_header( const fc::string& key )const; fc::string method; fc::string domain; fc::string path; @@ -39,6 +40,8 @@ namespace fc { fc::vector body; }; + fc::vector
parse_urlencoded_params( const fc::string& f ); + /** * Connections have reference semantics, all copies refer to the same * underlying socket. diff --git a/src/http_connection.cpp b/src/http_connection.cpp index 38b745e..b9cfb1b 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include FC_START_SHARED_IMPL(fc::http::connection) @@ -154,4 +156,42 @@ http::request connection::read_request()const { return req; } +fc::string request::get_header( const fc::string& key )const { + for( auto itr = headers.begin(); itr != headers.end(); ++itr ) { + if( itr->key == key ) { return itr->val; } + } + return fc::string(); +} +fc::vector
parse_urlencoded_params( const fc::string& f ) { + int num_args = 0; + for( size_t i = 0; i < f.size(); ++i ) { + if( f[i] == '=' ) ++num_args; + } + fc::vector
h(num_args); + int arg = 0; + for( size_t i = 0; i < f.size(); ++i ) { + while( f[i] != '=' && i < f.size() ) { + if( f[i] == '%' ) { + h[arg].key += char((fc::from_hex(f[i+1]) << 4) | fc::from_hex(f[i+2])); + i += 3; + } else { + h[arg].key += f[i]; + ++i; + } + } + ++i; + while( i < f.size() && f[i] != '&' ) { + if( f[i] == '%' ) { + h[arg].val += char((fc::from_hex(f[i+1]) << 4) | fc::from_hex(f[i+2])); + i += 3; + } else { + h[arg].val += f[i] == '+' ? ' ' : f[i]; + ++i; + } + } + ++arg; + } + return h; +} + } } // fc::http