bug fixes and improvements

This commit is contained in:
Daniel Larimer 2012-12-16 00:31:43 -05:00
parent 9a8767a645
commit efca814f0b
3 changed files with 44 additions and 3 deletions

View file

@ -1,5 +1,4 @@
#ifndef _FC_FILESYSTEM_HPP_
#define _FC_FILESYSTEM_HPP_
#pragma once
#include <fc/string.hpp>
#include <fc/fwd.hpp>
@ -72,4 +71,3 @@ namespace fc {
path temp_directory_path();
}
#endif // _FC_FILESYSTEM_HPP_

View file

@ -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<char> body;
};
fc::vector<header> parse_urlencoded_params( const fc::string& f );
/**
* Connections have reference semantics, all copies refer to the same
* underlying socket.

View file

@ -4,6 +4,8 @@
#include <fc/iostream.hpp>
#include <fc/exception.hpp>
#include <fc/ip.hpp>
#include <fc/error_report.hpp>
#include <fc/hex.hpp>
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<header> 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<header> 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