eidheim / Simple-Web-Server

A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.
MIT License
2.61k stars 751 forks source link

[feature] http2 support #72

Open iamthebot opened 8 years ago

iamthebot commented 8 years ago

I think a really nice addition to this library would be adding http2 support. This is particularly beneficial for high performance API applications since http2 supports multiplexing and has a lower overhead.

The first (easy) option: libnghttp2 has a mature implementation so the easier way forward would be to provide a wrapper so we could do something like:

SimpleWeb::Server<SimpleWeb::HTTP2> HttpServer;

Of course, that would make the library no longer header-only (which isn't a big deal IMO) and add a dependency.

The harder option: A custom http2 implementation. This would provide nicer integration and you could provide transparent backwards compatibility on a single endpoint this way.

Thoughts?

eidheim commented 8 years ago

It's a good idea, and I have thought about it, but the main issue is added complexity. Also, last time I had a look at the HTTP2 standard, the documentation seemed immature. It might have improved though.

That said, the goal for this project was to make a simple implementation of HTTP(S) for use with modern C++ that people could learn from (boost.asio is quite complicated) and possibly extend to their wishes and needs. Although, maybe the next step would be to do the same for HTTP2, but then the library will not be that simple anymore, but if we can separate the implementations that should not be a critical issue. I'll give it some more thought:)

Type1J commented 7 years ago

cURL delegates http2 support to the https://github.com/nghttp2/nghttp2 library, which I believe can be used for making a client, server, or proxy for http2. I know that it would introduce a dependency, but due to the complexity of http2, and it's desirability, it might be a good idea.

That being said, you can get most of the benefit that you might get by your app speaking http2 directly by using Nginx, which speaks http2, as a reverse proxy to your app. It can speak http1.1 to your app (very fast when you're nodes are on the same network) while maintaining an open http2 session to the remote client.

eidheim commented 7 years ago

@Type1J Thank you for the information, I'll have to look into this during the summer.