HTTP: Implement persistent connections (keep-alive) etc.#15053
HTTP: Implement persistent connections (keep-alive) etc.#15053DDvO wants to merge 14 commits intoopenssl:masterfrom
Conversation
e1ec2af to
6ddf09f
Compare
|
When submitting this PR some 2 days ago, I forgot to mention details about the proposed semantics of the new feature. Here they are:
For the CMP app the default value is 1, which means preferring to keep the connection open. If the client application requested or required a persistent connection and this was granted by the server, |
|
@openssl/otc, is there already someone willing to review this? |
|
BTW, I also have some high-level HTTP client API streamlining and generalization in the pipeline to be submitted as follow-up; |
|
I meanwhile found that specific tests for the new keep-alive feature can be added in a rather straightforward way, so done this as well. |
|
Also added a couple of related small fixes of the HTTP client implementation, |
|
Added a fixup on the documentation of |
|
Since so far I have not seen any reaction on this PR that would indicate that someone has started reviewing this, |
|
On this occasion I've updated the |
|
@openssl/otc, I am getting more and more concerned about how to get this PR approved and merged before the public API / feature freeze, which is going to be in 16 days from now. This PR, submitted 6 days ago, implements a feature discussed in #14004. It is critical for one of our customers in order to be able to make their product compliant with ERTMS/ECTS requirements by UNISIG. How to solve this? |
|
Rebased again to fix simple merge conflicts |
Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15053)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15053)
… URLs) Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15053)
Both at API and at CLI level (for the CMP app only, so far) there is a new parameter/option: keep_alive. * 0 means HTTP connections are not kept open after receiving a response, which is the default behavior for HTTP 1.0. * 1 means that persistent connections are requested. * 2 means that persistent connections are required, i.e., in case the server does not grant them an error occurs. For the CMP app the default value is 1, which means preferring to keep the connection open. For all other internal uses of the HTTP client (fetching an OCSP response, a cert, or a CRL) it does not matter because these operations just take one round trip. If the client application requested or required a persistent connection and this was granted by the server, it can keep the OSSL_HTTP_REQ_CTX * as long as it wants to send further requests and OSSL_HTTP_is_alive() returns nonzero, else it should call OSSL_HTTP_REQ_CTX_free() or OSSL_HTTP_close(). In case the client application keeps the OSSL_HTTP_REQ_CTX * but the connection then dies for any reason at the server side, it will notice this obtaining an I/O error when trying to send the next request. This requires extending the HTTP header parsing and rearranging the high-level HTTP client API. In particular: * Split the monolithic OSSL_HTTP_transfer() into OSSL_HTTP_open(), OSSL_HTTP_set_request(), a lean OSSL_HTTP_transfer(), and OSSL_HTTP_close(). * Split the timeout functionality accordingly and improve default behavior. * Extract part of OSSL_HTTP_REQ_CTX_new() to OSSL_HTTP_REQ_CTX_set_expected(). * Extend struct ossl_http_req_ctx_st accordingly. Use the new feature for the CMP client, which requires extending related transaction management of CMP client and test server. Update the documentation and extend the tests accordingly. Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15053)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15053)
Also improve doc of OSSL_parse_url() and OSSL_HTTP_parse_url(). Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15053)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15053)
Also clean up OSSL_HTTP_REQ_CTX_nbio() states and make it more efficient. Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15053)
…te length) Also clean up max_resp_len and add OSSL_HTTP_REQ_CTX_get_resp_len(). Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15053)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15053)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15053)
|
Merged - thanks a lot to all to contributed to being able to merge this PR in time! |
This is a minimal version of pull request openssl#15053 including all the proposed improvements to the HTTP client API and its documentation but only those code adaptations strictly needed for it. The proposed new features include * support for persistent connections (keep-alive), * generalization to arbitrary request and response types, and * support for streaming BIOs for request and response data. The related API changes include: * Split the monolithic OSSL_HTTP_transfer() into OSSL_HTTP_open(), OSSL_HTTP_set_request(), a lean OSSL_HTTP_transfer(), and OSSL_HTTP_close(). * Split the timeout functionality accordingly and improve default behavior. * Extract part of OSSL_HTTP_REQ_CTX_new() to OSSL_HTTP_REQ_CTX_set_expected(). Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15147)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
… URLs) Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
Both at API and at CLI level (for the CMP app only, so far) there is a new parameter/option: keep_alive. * 0 means HTTP connections are not kept open after receiving a response, which is the default behavior for HTTP 1.0. * 1 means that persistent connections are requested. * 2 means that persistent connections are required, i.e., in case the server does not grant them an error occurs. For the CMP app the default value is 1, which means preferring to keep the connection open. For all other internal uses of the HTTP client (fetching an OCSP response, a cert, or a CRL) it does not matter because these operations just take one round trip. If the client application requested or required a persistent connection and this was granted by the server, it can keep the OSSL_HTTP_REQ_CTX * as long as it wants to send further requests and OSSL_HTTP_is_alive() returns nonzero, else it should call OSSL_HTTP_REQ_CTX_free() or OSSL_HTTP_close(). In case the client application keeps the OSSL_HTTP_REQ_CTX * but the connection then dies for any reason at the server side, it will notice this obtaining an I/O error when trying to send the next request. This requires extending the HTTP header parsing and rearranging the high-level HTTP client API. In particular: * Split the monolithic OSSL_HTTP_transfer() into OSSL_HTTP_open(), OSSL_HTTP_set_request(), a lean OSSL_HTTP_transfer(), and OSSL_HTTP_close(). * Split the timeout functionality accordingly and improve default behavior. * Extract part of OSSL_HTTP_REQ_CTX_new() to OSSL_HTTP_REQ_CTX_set_expected(). * Extend struct ossl_http_req_ctx_st accordingly. Use the new feature for the CMP client, which requires extending related transaction management of CMP client and test server. Update the documentation and extend the tests accordingly. Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
Also improve doc of OSSL_parse_url() and OSSL_HTTP_parse_url(). Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
Also clean up OSSL_HTTP_REQ_CTX_nbio() states and make it more efficient. Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
…te length) Also clean up max_resp_len and add OSSL_HTTP_REQ_CTX_get_resp_len(). Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#15053)
This PR implements feature request #14004.
The proposed semantics of the new feature implemented here is as follows.
Both at API and at CLI level (for the CMP app only, so far) there is a new parameter/option:
keep_alive.For the CMP app the default value is 1, which means preferring to keep the connection open.
For all other internal uses of the HTTP client (fetching an OCSP response, a cert, or a CRL) it does not matter because these operations just take one round trip.
If the client application requested or required a persistent connection and this was granted by the server,
it can keep the
OSSL_HTTP_REQ_CTX *as long as it wants to send further requests andOSSL_HTTP_is_alive()returns nonzero,else it should call
OSSL_HTTP_REQ_CTX_free()orOSSL_HTTP_close().In case the client application keeps the
OSSL_HTTP_REQ_CTX *but the connection then dies for any reason at the server side, it will notice this obtaining an I/O error when trying to send the next request .This feature addition requires extending the HTTP header parsing and rearranging the high-level HTTP client API.
In particular:
OSSL_HTTP_transfer()intoOSSL_HTTP_open(),OSSL_HTTP_set_request(),a leanOSSL_HTTP_transfer(),andOSSL_HTTP_close().OSSL_HTTP_REQ_CTX_new()toOSSL_HTTP_REQ_CTX_set_expected().struct ossl_http_req_ctx_staccordingly.Also extend related diagnostic output for debugging.
Use the new feature for the CMP client,
which requires extending related transaction management of CMP client and test server.
Related further more general improvements (in separate commits) included because they are related:
OSSL_HTTP_get():Do not close connection if redirect to same serverOSSL_HTTP_REQ_CTX_add1_headers():Fix use withhost == NULL(relative URLs)OSSL_HTTP_transfer(): Fix error reporting in caserctx->server == NULL.Also improve doc of
OSSL_parse_url()andOSSL_HTTP_parse_url()IntroducingOSSL_HTTP_i2d()andOSSL_HTTP_d2i()makes the API more clear and modular.Also clean up
OSSL_HTTP_REQ_CTX_nbio() states and make it more efficient.Also clean up
max_resp_lenand addOSSL_HTTP_REQ_CTX_get_resp_len()maxlineparameter tobuf_sizefor clarity.http_client.cfor consistency.Checklist