2 * Copyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright Siemens AG 2018-2020
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
11 #ifndef OPENSSL_HTTP_H
12 # define OPENSSL_HTTP_H
15 # include <openssl/opensslconf.h>
17 # include <openssl/bio.h>
18 # include <openssl/asn1.h>
19 # include <openssl/conf.h>
26 # define OSSL_HTTP_NAME "http"
27 # define OSSL_HTTPS_NAME "https"
28 # define OSSL_HTTP_PREFIX OSSL_HTTP_NAME"://"
29 # define OSSL_HTTPS_PREFIX OSSL_HTTPS_NAME"://"
30 # define OSSL_HTTP_PORT "80"
31 # define OSSL_HTTPS_PORT "443"
32 # define OPENSSL_NO_PROXY "NO_PROXY"
33 # define OPENSSL_HTTP_PROXY "HTTP_PROXY"
34 # define OPENSSL_HTTPS_PROXY "HTTPS_PROXY"
36 # ifndef OPENSSL_NO_HTTP
38 #define OSSL_HTTP_DEFAULT_MAX_LINE_LEN (4 * 1024)
39 #define OSSL_HTTP_DEFAULT_MAX_RESP_LEN (100 * 1024)
41 /* Low-level HTTP API */
42 OSSL_HTTP_REQ_CTX
*OSSL_HTTP_REQ_CTX_new(BIO
*wbio
, BIO
*rbio
, int buf_size
);
43 void OSSL_HTTP_REQ_CTX_free(OSSL_HTTP_REQ_CTX
*rctx
);
44 int OSSL_HTTP_REQ_CTX_set_request_line(OSSL_HTTP_REQ_CTX
*rctx
, int method_POST
,
45 const char *server
, const char *port
,
47 int OSSL_HTTP_REQ_CTX_add1_header(OSSL_HTTP_REQ_CTX
*rctx
,
48 const char *name
, const char *value
);
49 int OSSL_HTTP_REQ_CTX_set_expected(OSSL_HTTP_REQ_CTX
*rctx
,
50 const char *content_type
, int asn1
,
51 int timeout
, int keep_alive
);
52 int OSSL_HTTP_REQ_CTX_set1_req(OSSL_HTTP_REQ_CTX
*rctx
, const char *content_type
,
53 const ASN1_ITEM
*it
, const ASN1_VALUE
*req
);
54 int OSSL_HTTP_REQ_CTX_nbio(OSSL_HTTP_REQ_CTX
*rctx
);
55 int OSSL_HTTP_REQ_CTX_nbio_d2i(OSSL_HTTP_REQ_CTX
*rctx
,
56 ASN1_VALUE
**pval
, const ASN1_ITEM
*it
);
57 BIO
*OSSL_HTTP_REQ_CTX_exchange(OSSL_HTTP_REQ_CTX
*rctx
);
58 BIO
*OSSL_HTTP_REQ_CTX_get0_mem_bio(const OSSL_HTTP_REQ_CTX
*rctx
);
59 size_t OSSL_HTTP_REQ_CTX_get_resp_len(const OSSL_HTTP_REQ_CTX
*rctx
);
60 void OSSL_HTTP_REQ_CTX_set_max_response_length(OSSL_HTTP_REQ_CTX
*rctx
,
62 int OSSL_HTTP_is_alive(const OSSL_HTTP_REQ_CTX
*rctx
);
64 /* High-level HTTP API */
65 typedef BIO
*(*OSSL_HTTP_bio_cb_t
)(BIO
*bio
, void *arg
, int connect
, int detail
);
66 OSSL_HTTP_REQ_CTX
*OSSL_HTTP_open(const char *server
, const char *port
,
67 const char *proxy
, const char *no_proxy
,
68 int use_ssl
, BIO
*bio
, BIO
*rbio
,
69 OSSL_HTTP_bio_cb_t bio_update_fn
, void *arg
,
70 int buf_size
, int overall_timeout
);
71 int OSSL_HTTP_proxy_connect(BIO
*bio
, const char *server
, const char *port
,
72 const char *proxyuser
, const char *proxypass
,
73 int timeout
, BIO
*bio_err
, const char *prog
);
74 int OSSL_HTTP_set1_request(OSSL_HTTP_REQ_CTX
*rctx
, const char *path
,
75 const STACK_OF(CONF_VALUE
) *headers
,
76 const char *content_type
, BIO
*req
,
77 const char *expected_content_type
, int expect_asn1
,
78 size_t max_resp_len
, int timeout
, int keep_alive
);
79 BIO
*OSSL_HTTP_exchange(OSSL_HTTP_REQ_CTX
*rctx
, char **redirection_url
);
80 BIO
*OSSL_HTTP_get(const char *url
, const char *proxy
, const char *no_proxy
,
82 OSSL_HTTP_bio_cb_t bio_update_fn
, void *arg
,
83 int buf_size
, const STACK_OF(CONF_VALUE
) *headers
,
84 const char *expected_content_type
, int expect_asn1
,
85 size_t max_resp_len
, int timeout
);
86 BIO
*OSSL_HTTP_transfer(OSSL_HTTP_REQ_CTX
**prctx
,
87 const char *server
, const char *port
,
88 const char *path
, int use_ssl
,
89 const char *proxy
, const char *no_proxy
,
91 OSSL_HTTP_bio_cb_t bio_update_fn
, void *arg
,
92 int buf_size
, const STACK_OF(CONF_VALUE
) *headers
,
93 const char *content_type
, BIO
*req
,
94 const char *expected_content_type
, int expect_asn1
,
95 size_t max_resp_len
, int timeout
, int keep_alive
);
96 int OSSL_HTTP_close(OSSL_HTTP_REQ_CTX
*rctx
, int ok
);
98 /* Auxiliary functions */
99 int OSSL_parse_url(const char *url
, char **pscheme
, char **puser
, char **phost
,
100 char **pport
, int *pport_num
,
101 char **ppath
, char **pquery
, char **pfrag
);
102 int OSSL_HTTP_parse_url(const char *url
, int *pssl
, char **puser
, char **phost
,
103 char **pport
, int *pport_num
,
104 char **ppath
, char **pquery
, char **pfrag
);
105 const char *OSSL_HTTP_adapt_proxy(const char *proxy
, const char *no_proxy
,
106 const char *server
, int use_ssl
);
109 # endif /* !defined(OPENSSL_NO_HTTP) */
113 #endif /* !defined(OPENSSL_HTTP_H) */