mirror of
https://github.com/openssl/openssl.git
synced 2024-11-27 05:21:51 +08:00
OSSL_HTTP_REQ_CTX_new(): replace method_GET parameter by method_POST
Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/13898)
This commit is contained in:
parent
cddbcf02f5
commit
046fba4493
@ -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;
|
||||
}
|
||||
|
@ -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<OSSL_HTTP_get(3)> and L<OSSL_HTTP_transfer(3)>
|
||||
should be preferred.
|
||||
|
||||
OSSL_HTTP_REQ_CTX_new() allocates a new HTTP request context structure, which
|
||||
gets populated with the B<BIO> to send the request to (I<wbio>), the B<BIO> to
|
||||
read the response from (I<rbio>, which may be the same as I<wbio>), the
|
||||
request method (I<method_GET>, which may be 1 to indicate that the C<GET>
|
||||
method is to be used, or 0 to indicate that the C<POST> method is to be used),
|
||||
the maximum expected response header length (I<max_resp_len>, where any zero
|
||||
or less indicates the default of 4KiB), a response timeout measure in seconds
|
||||
(I<timeout>, where 0 indicates no timeout, i.e., waiting indefinitely), the
|
||||
expected MIME content type of the response (I<expected_content_type>, 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<expect_asn1>).
|
||||
OSSL_HTTP_REQ_CTX_new() allocates a new HTTP request context structure,
|
||||
which gets populated with the B<BIO> to send the request to (I<wbio>),
|
||||
the B<BIO> to read the response from (I<rbio>, which may be equal to I<wbio>),
|
||||
the request method (I<method_POST>, which may be 1 to indicate that the C<POST>
|
||||
method is to be used, or 0 to indicate that the C<GET> method is to be used),
|
||||
the maximum expected response header length (I<max_resp_len>,
|
||||
where any zero or less indicates the default of 4KiB),
|
||||
a response timeout measure in seconds (I<timeout>,
|
||||
where 0 indicates no timeout, i.e., waiting indefinitely),
|
||||
the expected MIME content type of the response (I<expected_content_type>,
|
||||
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<expect_asn1>).
|
||||
The allocated context structure is also populated with an internal allocated
|
||||
memory B<BIO>, 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<wbio> and I<rbio> 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<GET> or C<POST> depending on the value
|
||||
of I<method_GET> in the OSSL_HTTP_REQ_CTX_new() call. I<server> and I<port>
|
||||
The request method itself becomes C<GET> or C<POST> depending on the value
|
||||
of I<method_POST> in the OSSL_HTTP_REQ_CTX_new() call. I<server> and I<port>
|
||||
may be set to indicate a proxy server and port that the request should go
|
||||
through, otherwise they should be left NULL. I<path> is the HTTP request path;
|
||||
if left NULL, C</> is used.
|
||||
@ -90,8 +92,8 @@ encoding of I<req>, using the ASN.1 template I<it> to do the encoding. The
|
||||
HTTP header C<Content-Length> is automatically filled out, and if
|
||||
I<content_type> isn't NULL, the HTTP header C<Content-Type> is also added with
|
||||
its content as value. All of this ends up in the internal memory B<BIO>.
|
||||
This requires that the request type be C<POST>, i.e. that I<method_GET> is 0
|
||||
in the OSSL_HTTP_REQ_CTX_new() call.
|
||||
This requires that the request type be C<POST>,
|
||||
i.e., that I<method_POST> 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<rbio> and I<wbio> 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<POST> data with OSSL_HTTP_REQ_CTX_i2d(). This may only be done if
|
||||
I<method_GET> was 0 in the OSSL_HTTP_REQ_CTX_new() call, and must be done
|
||||
I<method_POST> was 1 in the OSSL_HTTP_REQ_CTX_new() call, and must be done
|
||||
exactly once in that case.
|
||||
|
||||
=back
|
||||
|
Loading…
Reference in New Issue
Block a user