Stiffstream / restinio

Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use
Other
1.15k stars 93 forks source link

Determine server traits when handling a request/building response #102

Closed prince-chrismc closed 4 years ago

prince-chrismc commented 4 years ago

I am trying to add support for HSTS, however my request_handler_ts are blissfully unaware of the server and what protocol it is configured to run with yet they are the one with the job of building the response dependent on it;s configuration.

Would it be possible to have a bool request_handle_t::is_tls_connection() const method?

We have access to the connection_id_t from a request, but I can not find anything meaningful to use that information.

Any directions on how I could go about this will be appreciated =)

eao197 commented 4 years ago

I think there are two options that don't require to change RESTinio's implementation:

  1. You pass a flag to your request handlers that indicate a type of connection to be handled. RESTinio's sever can be either non-SSL or SSL. It means that you can't have non-SSL and SSL connections at the same RESTinio's server. That allows you to store a flag nonSSL/SSL somewhere and check that flag in your request handlers.
  2. You can implement your own connection-state listener and maintain a dictionary of connection IDs and connection properties. That dictionary will be modified by your connection-state listener and that dictionary can be examined in your request handlers.

An introduction of is_tls_connection to request_t is possible (but I don't yet know is it's a good idea or not, and does it require another step of providing access to some TLS-related information from a connection or not). This idea requires some additional investigation. Unfortunately, we won't have time for it in the next couple of weeks because all our resources are allocated to an urgent project. I'm sorry.

prince-chrismc commented 4 years ago

An introduction of is_tls_connection to request_t is possible (but I don't yet know is it's a good idea or not, and does it require another step of providing access to some TLS-related information from a connection or not).

I would tend to agree with you, is does not feel like the role of the request to know the underlying protocol.

  1. You pass a flag to your request handlers that indicate a type of connection to be handled. RESTinio's sever can be either non-SSL or SSL.

I don't like this either but it makes much more sense then having it on the request. It's not totally unreasonable that an API knows where its HTTP or HTTPS

This idea requires some additional investigation. Unfortunately, we won't have time for it in the next couple of weeks because all our resources are allocated to an urgent project. I'm sorry.

That is absolutely alright! I appreciate the quick response, it certainly confirmed my suspicion that there was no API for doing this.