Skip to content

Commit

Permalink
Clear request before requesting
Browse files Browse the repository at this point in the history
  • Loading branch information
windoze committed Aug 27, 2015
1 parent 2892934 commit ec1cb9c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/fibio/http/client/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ namespace fibio { namespace http {
const common::header_map &hdr=common::header_map(),
unsigned max_redirection=50)
{
the_request_.clear();
if(prepare(url)) {
the_request_.method(http_method::GET);
if (!hdr.empty()) the_request_.headers.insert(hdr.begin(), hdr.end());
Expand All @@ -114,6 +115,7 @@ namespace fibio { namespace http {
const common::header_map &hdr=common::header_map(),
unsigned max_redirection=std::numeric_limits<unsigned>::max())
{
the_request_.clear();
if(prepare(url)) {
the_request_.method(http_method::POST).content_type("application/x-www-form-urlencoded");
// Write URL encoded body into body stream
Expand Down
8 changes: 5 additions & 3 deletions test/test_http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,27 @@ void the_client() {

void the_url_client() {
url_client uc;
if(0)
{
client::response &resp=uc.request("http://0d0a.com/");
assert(resp.status_code==http_status_code::OK);
}
if(0)
{
client::response &resp=uc.request("http://www.baidu.com/");
assert(resp.status_code==http_status_code::OK);
}
{
// http://http://www.wikipedia.org// responses with 302, redirects to 'https://http://www.wikipedia.org//'
client::response &resp=uc.request("http://http://www.wikipedia.org//");
// http://github.com/ responses with 302, redirects to 'https://github.com/'
client::response &resp=uc.request("http://github.com/");
assert(resp.status_code==http_status_code::OK);
}
}

int fibio::main(int argc, char *argv[]) {
fiber_group fibers;
for (int i=0; i<1; i++) {
fibers.create_fiber(the_client);
//fibers.create_fiber(the_client);
fibers.create_fiber(the_url_client);
}
fibers.join_all();
Expand Down

0 comments on commit ec1cb9c

Please sign in to comment.