-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Post AMQP events via strand to reduce threading issues * HTTP updates including stall timeout and connection recycling
- Loading branch information
Showing
41 changed files
with
32,278 additions
and
633 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
|
||
line_stream("\n"), "\x0D\x0A" | ||
|
||
line_stream takes a char_stream. It collects characters until the linebreak, at which point it emits those characters. | ||
|
||
auto ls = line_stream(cs); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Protocol format | ||
|
||
Latest information seems to be [https://github.com/b/statsd_spec](here). | ||
|
||
This is a line-based protocol. | ||
|
||
key:value|type | ||
|
||
Types are: | ||
|
||
* g - gauge, instantaneous value | ||
* c - counter, inc/dec, also supports rate (|@rate) | ||
* ms - timer | ||
* h - histogram, alias for timer | ||
* m - meter, rate | ||
|
||
A key with no other information should be treated as a meter with value of 1. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
void | ||
example() | ||
{ | ||
auto client = net::asio::tcp::client(); | ||
client->connect( | ||
"localhost", | ||
80 | ||
)->then( | ||
[](std::shared_ptr<stream> s) { | ||
s->sink([](const std::string &in) { | ||
std::cout << in; | ||
}); | ||
return s->write( | ||
"GET / HTTP/1.1\x0D\x0A\x0D\x0A" | ||
)->then( | ||
[s](size_t written) { | ||
return s->remote_eof(); | ||
} | ||
); | ||
} | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <net/asio/http.h> | ||
|
||
int | ||
main(int argc, const char *argv[]) | ||
{ | ||
boost::asio::io_service service { }; | ||
auto client_ = std::make_shared<net::http::client>(service); | ||
bool show_request = false; | ||
bool show_headers = false; | ||
for(int i = 1; i < argc; ++i) { | ||
auto v = std::string { argv[i] }; | ||
if(v == "--headers") { | ||
show_headers = true; | ||
} else if(v == "--request") { | ||
show_request = true; | ||
} else { | ||
auto req = net::http::request { | ||
net::http::uri { | ||
argv[i] | ||
} | ||
}; | ||
req << net::http::header("User-agent", "some-user-agent"); | ||
auto res = client_->GET( | ||
std::move(req) | ||
); | ||
res->completion()->on_done([i, show_request, show_headers](const std::shared_ptr<net::http::response> &res) { | ||
if(show_request) { | ||
std::cout << res->request().bytes() << "\n"; | ||
} | ||
if(show_headers) { | ||
res->each_header([](const net::http::header &h) { | ||
std::cout << h.key() << ": " << h.value() << "\n"; | ||
}); | ||
std::cout << "\n"; | ||
} | ||
std::cout << res->body(); | ||
}); | ||
} | ||
} | ||
|
||
// std::cout << "run\n"; | ||
service.run(); | ||
// std::cout << "done\n"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# HTTP | ||
|
||
Some basic implementation details: | ||
|
||
## GET /path => empty | ||
|
||
return client_.get(uri) | ||
->expect_status(200, 201, 202, 204) | ||
->ignore_body() | ||
->completion(); | ||
|
||
## GET /path => binary | ||
|
||
return client_.get(uri) | ||
->expect_status(200, 201, 202, 204) | ||
->stream_body([ca](const std::string &in) { | ||
return ca->append_body(in); | ||
}) | ||
->completion(); | ||
|
||
## GET /path => JSON | ||
|
||
return client_.get(uri) | ||
->expect_status(200, 201, 202, 204) | ||
->expect_content_type("application/javascript") | ||
->completion(); | ||
json::parse(resp->body()); | ||
|
||
## JSON => POST /path => JSON | ||
|
||
return client_.get(uri) | ||
->expect_status(200, 201, 202, 204) | ||
->expect_content_type("application/javascript") | ||
->body(json_in) | ||
->completion(); | ||
json::parse(resp->body()); | ||
|
||
## PB => POST /path | ||
|
Oops, something went wrong.