Skip to content

Commit

Permalink
Update documents using updated libnghttp2_asio API, including client API
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Mar 6, 2015
1 parent 66f5438 commit 76eb319
Show file tree
Hide file tree
Showing 7 changed files with 370 additions and 107 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ doc/tutorial-hpack.rst
doc/python-apiref.rst
doc/building-android-binary.rst
doc/asio_http2.h.rst
doc/asio_http2_server.h.rst
doc/asio_http2_client.h.rst
doc/libnghttp2_asio.rst
doc/contribute.rst
python/setup.py
Expand Down
52 changes: 52 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,58 @@ HTTP/2 server looks like this:
}
}
Here is the sample code for client API use:

.. code-block:: cpp
#include <iostream>
#include <nghttp2/asio_http2_client.h>
using boost::asio::ip::tcp;
using namespace nghttp2::asio_http2;
using namespace nghttp2::asio_http2::client;
int main(int argc, char *argv[]) {
boost::system::error_code ec;
boost::asio::io_service io_service;
// connect to localhost:3000
session sess(io_service, "localhost", "3000");
sess.on_connect([&sess](tcp::resolver::iterator endpoint_it) {
boost::system::error_code ec;
auto req = sess.submit(ec, "GET", "http://localhost:3000/");
req->on_response([](const response &res) {
// print status code and response header fields.
std::cerr << "HTTP/2 " << res.status_code() << std::endl;
for (auto &kv : res.header()) {
std::cerr << kv.first << ": " << kv.second.value << "\n";
}
std::cerr << std::endl;
res.on_data([](const uint8_t *data, std::size_t len) {
std::cerr.write(reinterpret_cast<const char *>(data), len);
std::cerr << std::endl;
});
});
req->on_close([&sess](uint32_t error_code) {
// shutdown session after first request was done.
sess.shutdown();
});
});
sess.on_error([](const boost::system::error_code &ec) {
std::cerr << "error: " << ec.message() << std::endl;
});
io_service.run();
}
For more details, see the documentation of libnghttp2_asio.

Python bindings
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ AC_CONFIG_FILES([
doc/nghttp2.h.rst
doc/nghttp2ver.h.rst
doc/asio_http2.h.rst
doc/asio_http2_server.h.rst
doc/asio_http2_client.h.rst
doc/contribute.rst
contrib/Makefile
])
Expand Down
5 changes: 5 additions & 0 deletions doc/asio_http2_client.h.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
asio_http2_client.h
===================

.. literalinclude:: @top_srcdir@/src/includes/nghttp2/asio_http2_client.h
:language: cpp
5 changes: 5 additions & 0 deletions doc/asio_http2_server.h.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
asio_http2_server.h
===================

.. literalinclude:: @top_srcdir@/src/includes/nghttp2/asio_http2_server.h
:language: cpp
2 changes: 2 additions & 0 deletions doc/sources/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Contents:
python-apiref
nghttp2.h
nghttp2ver.h
asio_http2_server.h
asio_http2_client.h
asio_http2.h
Source <https://github.com/tatsuhiro-t/nghttp2>
Issues <https://github.com/tatsuhiro-t/nghttp2/issues>
Expand Down
Loading

0 comments on commit 76eb319

Please sign in to comment.