|
From: | silvioprog |
Subject: | Re: [libmicrohttpd] HTTP2 support for MHD |
Date: | Fri, 30 Mar 2018 12:27:03 -0300 |
Hello everyone,
My name is Maru and in the last few months I've been implementing HTTP2
support for MHD, as a personal programming project.
https://github.com/maru/libmicrohttpd-http2
I've just finished a first alpha release, so I wanted to share my work
with you.
Some implementation details:
- I chose the library nghttp2 for handling the HTTP/2 protocol. It works
with byte strings (input and output), leaving the handling of I/O
operations to the user. It is widely used in other projects, such as
curl and Apache httpd.
- I wanted to implement HTTP2 in the least "intrusive" way possible.
HTTP2 support is disabled by default, and HTTP2 code is only available
when HTTP2 is enabled.
- I followed the HTTPS implementation:
- enable HTTP2 in the configure script,
- use #ifdef in the MHD legacy code,
- all the implementation code is in the connection_http2.{c,h} files
(connection_http2_helper.h code is only for debug purposes).
To test the HTTP2 protocol, I used h2spec https://github.com/summerwind/h2spec .
It is a conformance testing tool for HTTP/2 implementation. It is
compliant with RFC 7540 (HTTP/2) http://www.rfc-editor.org/rfc/rfc7540.txt
and RFC 7541 (HPACK) http://www.rfc-editor.org/rfc/rfc7541.txt .
I also modified the existing MHD tests, so the server and client use HTTP2.
The use of HTTP2 is very simple and straightforward:
- User just adds "MHD_USE_HTTP2" flag when calling MHD_start_daemon.
- HTTP2 server settings can be modified using the MHD_OPTION_H2_SETTINGS
option (see src/examples/minimal_example.c).
Changes:
- Tests: daemons (and curl clients) run in HTTP1 and HTTP2 mode.
- src/examples/: can enable HTTP2 support with the command line option "-h2".
- Added some functions in src/microhttpd/test_helpers.h
- Example of adding a trailer in src/examples/chunked_example.c
- Implemented TLS-ALPN (allows protocol negotiation during the TLS handshake).
- Added HTTP2 connection states to MHD_CONNECTION_STATE (but not sure of
its usefulness).
To do:
- Modify the http2_stream structure. It's very ugly and messy...
- Allow HTTP1 upgrades to HTTP2 (right now, MHD only handles one version:
HTTP1 or HTTP2).
- Improve the performance.
- More HTTP2-related tests.
- Handle suspend/resume actions correctly (now implemented for only one stream).
- Finish the verbose/debugging information of sessions and frames (I like
the format used in nghttp client/server).
Finally: I pulled all the last commits in libmicrohttpd, and merged them
with my code. All tests and examples were run on Linux and passed!
I followed the coding style of MHD, but there might be incorrectly
formatted line lengths/variable names/braces.
How to build MHD with HTTP2 support:
- First, download the library nghttp2:
(I used version 1.24.0 for the development, but I also tested MHD with
the last release v1.31.0)
https://github.com/nghttp2/nghttp2/releases
The following package is required to build the libnghttp2 library:
pkg-config >= 0.20
You can build nghttp2:
configure --prefix=${PREFIX_DIR} --enable-lib-only
make && make install
- To run the curl tests, install a curl version 7.49.0 (with newer
releases, some HTTP2 tests fail: test_timeout_http2 and
test_get_response_cleanup_http2. I will investigate).
https://curl.haxx.se/download/curl-7.49.0.tar.gz
You can build libcurl:
configure --prefix=${PREFIX_DIR} --with-nghttp2=${PREFIX_DIR} --without-ssl --with-gnutls
make && make install
- Download libmicrohttpd-http2:
https://github.com/maru/libmicrohttpd-http2/archive/ v0.1.0.tar.gz
- I also set:
export LD_LIBRARY_PATH=${PREFIX_DIR}/lib
- To enable HTTP2 in MHD, you need to configure it:
configure --enable-http2 --with-nghttp2=${PREFIX_DIR}
- Finally, run:
make && make check
All comments, questions, and suggestions are more than welcome!
Best regards,
Maru
[Prev in Thread] | Current Thread | [Next in Thread] |