summaryrefslogtreecommitdiffstats
path: root/crypto/http
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-06-09 09:35:32 +0200
committerDr. David von Oheimb <dev@ddvo.net>2021-06-11 14:41:20 +0200
commit95c0b295dea8861a91873653e86636bebbbae65e (patch)
tree845139d4bbe3c5d2d6bc6b2e871752588a70feb6 /crypto/http
parent8c5bff2220c4f39b48660afda40005871f53250d (diff)
HTTP client: Fix GET request handling when rctx is reused (keep-alive)
This also updates the documentation of OSSL_HTTP_REQ_CTX_set1_req(). Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15697)
Diffstat (limited to 'crypto/http')
-rw-r--r--crypto/http/http_client.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/crypto/http/http_client.c b/crypto/http/http_client.c
index 79fe9ccd41..0906818451 100644
--- a/crypto/http/http_client.c
+++ b/crypto/http/http_client.c
@@ -200,9 +200,13 @@ int OSSL_HTTP_REQ_CTX_set_request_line(OSSL_HTTP_REQ_CTX *rctx, int method_POST,
path = "/";
if (path[0] != '/' && BIO_printf(rctx->mem, "/") <= 0)
return 0;
-
+ /*
+ * Add (the rest of) the path and the HTTP version,
+ * which is fixed to 1.0 for straightforward implementation of keep-alive
+ */
if (BIO_printf(rctx->mem, "%s "HTTP_1_0"\r\n", path) <= 0)
return 0;
+
rctx->resp_len = 0;
rctx->state = OHS_ADD_HEADERS;
return 1;
@@ -275,6 +279,8 @@ static int set1_content(OSSL_HTTP_REQ_CTX *rctx,
&& !OSSL_HTTP_REQ_CTX_add1_header(rctx, "Connection", "keep-alive"))
return 0;
+ BIO_free(rctx->req);
+ rctx->req = NULL;
if (req == NULL)
return 1;
if (!rctx->method_POST) {
@@ -287,11 +293,9 @@ static int set1_content(OSSL_HTTP_REQ_CTX *rctx,
return 0;
/* streaming BIO may not support querying size */
- if ((req_len = BIO_ctrl(req, BIO_CTRL_INFO, 0, NULL)) <= 0
- || BIO_printf(rctx->mem, "Content-Length: %ld\r\n", req_len) > 0) {
- if (!BIO_up_ref(req))
- return 0;
- BIO_free(rctx->req);
+ if (((req_len = BIO_ctrl(req, BIO_CTRL_INFO, 0, NULL)) <= 0
+ || BIO_printf(rctx->mem, "Content-Length: %ld\r\n", req_len) > 0)
+ && BIO_up_ref(req)) {
rctx->req = req;
return 1;
}
@@ -301,16 +305,12 @@ static int set1_content(OSSL_HTTP_REQ_CTX *rctx,
int OSSL_HTTP_REQ_CTX_set1_req(OSSL_HTTP_REQ_CTX *rctx, const char *content_type,
const ASN1_ITEM *it, const ASN1_VALUE *req)
{
- BIO *mem;
- int res;
-
- if (rctx == NULL || it == NULL || req == NULL) {
- ERR_raise(ERR_LIB_HTTP, ERR_R_PASSED_NULL_PARAMETER);
- return 0;
- }
+ BIO *mem = NULL;
+ int res = 1;
- res = (mem = ASN1_item_i2d_mem_bio(it, req)) != NULL
- && set1_content(rctx, content_type, mem);
+ if (req != NULL)
+ res = (mem = ASN1_item_i2d_mem_bio(it, req)) != NULL;
+ res = res && set1_content(rctx, content_type, mem);
BIO_free(mem);
return res;
}