From 046fba4493d6cb17e0b8b22f43d5ee63c2ff8d50 Mon Sep 17 00:00:00 2001 From: "Dr. David von Oheimb" Date: Mon, 18 Jan 2021 12:37:47 +0100 Subject: OSSL_HTTP_REQ_CTX_new(): replace method_GET parameter by method_POST Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/13898) --- crypto/http/http_client.c | 14 +++++++------- doc/man3/OSSL_HTTP_REQ_CTX.pod | 36 +++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/crypto/http/http_client.c b/crypto/http/http_client.c index 9cde88d2e6..a718b3678d 100644 --- a/crypto/http/http_client.c +++ b/crypto/http/http_client.c @@ -47,7 +47,7 @@ struct ossl_http_req_ctx_st { BIO *wbio; /* BIO to send request to */ BIO *rbio; /* BIO to read response from */ BIO *mem; /* Memory BIO response is built into */ - int method_GET; /* HTTP method "GET" or "POST" */ + int method_POST; /* HTTP method is "POST" (else "GET") */ const char *expected_ct; /* expected Content-Type, or NULL */ int expect_asn1; /* response must be ASN.1-encoded */ unsigned long resp_len; /* length of response */ @@ -75,7 +75,7 @@ struct ossl_http_req_ctx_st { #define OHS_HTTP_HEADER (9 | OHS_NOREAD) /* Headers set, w/o final \r\n */ OSSL_HTTP_REQ_CTX *OSSL_HTTP_REQ_CTX_new(BIO *wbio, BIO *rbio, - int method_GET, int maxline, + int method_POST, int maxline, unsigned long max_resp_len, int timeout, const char *expected_content_type, @@ -100,7 +100,7 @@ OSSL_HTTP_REQ_CTX *OSSL_HTTP_REQ_CTX_new(BIO *wbio, BIO *rbio, OSSL_HTTP_REQ_CTX_free(rctx); return NULL; } - rctx->method_GET = method_GET; + rctx->method_POST = method_POST; rctx->expected_ct = expected_content_type; rctx->expect_asn1 = expect_asn1; rctx->resp_len = 0; @@ -150,7 +150,7 @@ int OSSL_HTTP_REQ_CTX_set_request_line(OSSL_HTTP_REQ_CTX *rctx, return 0; } - if (BIO_printf(rctx->mem, "%s ", rctx->method_GET ? "GET" : "POST") <= 0) + if (BIO_printf(rctx->mem, "%s ", rctx->method_POST ? "POST" : "GET") <= 0) return 0; if (server != NULL) { /* HTTP (but not HTTPS) proxy is used */ @@ -208,7 +208,7 @@ static int OSSL_HTTP_REQ_CTX_content(OSSL_HTTP_REQ_CTX *rctx, ERR_raise(ERR_LIB_HTTP, ERR_R_PASSED_NULL_PARAMETER); return 0; } - if (rctx->method_GET) { + if (!rctx->method_POST) { ERR_raise(ERR_LIB_HTTP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return 0; } @@ -304,7 +304,7 @@ OSSL_HTTP_REQ_CTX *HTTP_REQ_CTX_new(BIO *wbio, BIO *rbio, int use_http_proxy, } /* remaining parameters are checked indirectly by the functions called */ - if ((rctx = OSSL_HTTP_REQ_CTX_new(wbio, rbio, req_mem == NULL, maxline, + if ((rctx = OSSL_HTTP_REQ_CTX_new(wbio, rbio, req_mem != NULL, maxline, max_resp_len, timeout, expected_content_type, expect_asn1)) == NULL) @@ -543,7 +543,7 @@ int OSSL_HTTP_REQ_CTX_nbio(OSSL_HTTP_REQ_CTX *rctx) goto next_line; case HTTP_STATUS_CODE_MOVED_PERMANENTLY: case HTTP_STATUS_CODE_FOUND: /* i.e., moved temporarily */ - if (rctx->method_GET) { + if (!rctx->method_POST) { /* method is GET */ rctx->state = OHS_REDIRECT; goto next_line; } diff --git a/doc/man3/OSSL_HTTP_REQ_CTX.pod b/doc/man3/OSSL_HTTP_REQ_CTX.pod index dc7020c826..d5188895bc 100644 --- a/doc/man3/OSSL_HTTP_REQ_CTX.pod +++ b/doc/man3/OSSL_HTTP_REQ_CTX.pod @@ -21,7 +21,7 @@ OSSL_HTTP_REQ_CTX_set_max_response_length typedef struct ossl_http_req_ctx_st OSSL_HTTP_REQ_CTX; OSSL_HTTP_REQ_CTX *OSSL_HTTP_REQ_CTX_new(BIO *wbio, BIO *rbio, - int method_GET, int maxline, + int method_POST, int maxline, unsigned long max_resp_len, int timeout, const char *expected_content_type, @@ -53,17 +53,19 @@ This file documents low-level HTTP functions rarely used directly. High-level HTTP client functions like L and L should be preferred. -OSSL_HTTP_REQ_CTX_new() allocates a new HTTP request context structure, which -gets populated with the B to send the request to (I), the B to -read the response from (I, which may be the same as I), the -request method (I, which may be 1 to indicate that the C -method is to be used, or 0 to indicate that the C method is to be used), -the maximum expected response header length (I, where any zero -or less indicates the default of 4KiB), a response timeout measure in seconds -(I, where 0 indicates no timeout, i.e., waiting indefinitely), the -expected MIME content type of the response (I, which -may be NULL for no expectation), and a flag indicating that the response is -expected to be a DER encoded ASN.1 structure (I). +OSSL_HTTP_REQ_CTX_new() allocates a new HTTP request context structure, +which gets populated with the B to send the request to (I), +the B to read the response from (I, which may be equal to I), +the request method (I, which may be 1 to indicate that the C +method is to be used, or 0 to indicate that the C method is to be used), +the maximum expected response header length (I, +where any zero or less indicates the default of 4KiB), +a response timeout measure in seconds (I, +where 0 indicates no timeout, i.e., waiting indefinitely), +the expected MIME content type of the response (I, +which may be NULL for no expectation), +and a flag indicating that the response is expected to be +a DER encoded ASN.1 structure (I). The allocated context structure is also populated with an internal allocated memory B, which collects the HTTP request and additional headers as text. The returned context should only be used for a single HTTP request/response. @@ -73,8 +75,8 @@ The I and I are not free'd and it is up to the application to do so. OSSL_HTTP_REQ_CTX_set_request_line() adds the HTTP request line to the context. -The request command itself becomes C or C depending on the value -of I in the OSSL_HTTP_REQ_CTX_new() call. I and I +The request method itself becomes C or C depending on the value +of I in the OSSL_HTTP_REQ_CTX_new() call. I and I may be set to indicate a proxy server and port that the request should go through, otherwise they should be left NULL. I is the HTTP request path; if left NULL, C is used. @@ -90,8 +92,8 @@ encoding of I, using the ASN.1 template I to do the encoding. The HTTP header C is automatically filled out, and if I isn't NULL, the HTTP header C is also added with its content as value. All of this ends up in the internal memory B. -This requires that the request type be C, i.e. that I is 0 -in the OSSL_HTTP_REQ_CTX_new() call. +This requires that the request type be C, +i.e., that I is 1 in the OSSL_HTTP_REQ_CTX_new() call. OSSL_HTTP_REQ_CTX_nbio() attempts the exchange of request and response via HTTP, using the I and I that were given in the OSSL_HTTP_REQ_CTX_new() @@ -138,7 +140,7 @@ Adding extra headers with OSSL_HTTP_REQ_CTX_add1_header(). This is optional. =item 3. Add C data with OSSL_HTTP_REQ_CTX_i2d(). This may only be done if -I was 0 in the OSSL_HTTP_REQ_CTX_new() call, and must be done +I was 1 in the OSSL_HTTP_REQ_CTX_new() call, and must be done exactly once in that case. =back -- cgit v1.2.3