http.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright 2000-2025 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright Siemens AG 2018-2020
  4. *
  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
  9. */
  10. #ifndef OPENSSL_HTTP_H
  11. #define OPENSSL_HTTP_H
  12. #pragma once
  13. #include <openssl/opensslconf.h>
  14. #include <openssl/bio.h>
  15. #include <openssl/asn1.h>
  16. #include <openssl/conf.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #define OSSL_HTTP_NAME "http"
  21. #define OSSL_HTTPS_NAME "https"
  22. #define OSSL_HTTP_PREFIX OSSL_HTTP_NAME "://"
  23. #define OSSL_HTTPS_PREFIX OSSL_HTTPS_NAME "://"
  24. #define OSSL_HTTP_PORT "80"
  25. #define OSSL_HTTPS_PORT "443"
  26. #define OPENSSL_NO_PROXY "NO_PROXY"
  27. #define OPENSSL_HTTP_PROXY "HTTP_PROXY"
  28. #define OPENSSL_HTTPS_PROXY "HTTPS_PROXY"
  29. /* We want to have this even in case of OPENSSL_NO_HTTP */
  30. int OSSL_parse_url(const char *url, char **pscheme, char **puser, char **phost,
  31. char **pport, int *pport_num,
  32. char **ppath, char **pquery, char **pfrag);
  33. #ifndef OPENSSL_NO_HTTP
  34. #define OSSL_HTTP_DEFAULT_MAX_LINE_LEN (4 * 1024)
  35. #define OSSL_HTTP_DEFAULT_MAX_RESP_LEN (100 * 1024)
  36. #define OSSL_HTTP_DEFAULT_MAX_CRL_LEN (32 * 1024 * 1024)
  37. #define OSSL_HTTP_DEFAULT_MAX_RESP_HDR_LINES 256
  38. /* Low-level HTTP API */
  39. OSSL_HTTP_REQ_CTX *OSSL_HTTP_REQ_CTX_new(BIO *wbio, BIO *rbio, int buf_size);
  40. void OSSL_HTTP_REQ_CTX_free(OSSL_HTTP_REQ_CTX *rctx);
  41. int OSSL_HTTP_REQ_CTX_set_request_line(OSSL_HTTP_REQ_CTX *rctx, int method_POST,
  42. const char *server, const char *port,
  43. const char *path);
  44. int OSSL_HTTP_REQ_CTX_add1_header(OSSL_HTTP_REQ_CTX *rctx,
  45. const char *name, const char *value);
  46. int OSSL_HTTP_REQ_CTX_set_expected(OSSL_HTTP_REQ_CTX *rctx,
  47. const char *content_type, int asn1,
  48. int timeout, int keep_alive);
  49. int OSSL_HTTP_REQ_CTX_set1_req(OSSL_HTTP_REQ_CTX *rctx, const char *content_type,
  50. const ASN1_ITEM *it, const ASN1_VALUE *req);
  51. int OSSL_HTTP_REQ_CTX_nbio(OSSL_HTTP_REQ_CTX *rctx);
  52. int OSSL_HTTP_REQ_CTX_nbio_d2i(OSSL_HTTP_REQ_CTX *rctx,
  53. ASN1_VALUE **pval, const ASN1_ITEM *it);
  54. BIO *OSSL_HTTP_REQ_CTX_exchange(OSSL_HTTP_REQ_CTX *rctx);
  55. BIO *OSSL_HTTP_REQ_CTX_get0_mem_bio(const OSSL_HTTP_REQ_CTX *rctx);
  56. size_t OSSL_HTTP_REQ_CTX_get_resp_len(const OSSL_HTTP_REQ_CTX *rctx);
  57. void OSSL_HTTP_REQ_CTX_set_max_response_length(OSSL_HTTP_REQ_CTX *rctx,
  58. unsigned long len);
  59. void OSSL_HTTP_REQ_CTX_set_max_response_hdr_lines(OSSL_HTTP_REQ_CTX *rctx,
  60. size_t count);
  61. int OSSL_HTTP_is_alive(const OSSL_HTTP_REQ_CTX *rctx);
  62. /* High-level HTTP API */
  63. typedef BIO *(*OSSL_HTTP_bio_cb_t)(BIO *bio, void *arg, int connect, int detail);
  64. OSSL_HTTP_REQ_CTX *OSSL_HTTP_open(const char *server, const char *port,
  65. const char *proxy, const char *no_proxy,
  66. int use_ssl, BIO *bio, BIO *rbio,
  67. OSSL_HTTP_bio_cb_t bio_update_fn, void *arg,
  68. int buf_size, int overall_timeout);
  69. int OSSL_HTTP_proxy_connect(BIO *bio, const char *server, const char *port,
  70. const char *proxyuser, const char *proxypass,
  71. int timeout, BIO *bio_err, const char *prog);
  72. int OSSL_HTTP_set1_request(OSSL_HTTP_REQ_CTX *rctx, const char *path,
  73. const STACK_OF(CONF_VALUE) *headers,
  74. const char *content_type, BIO *req,
  75. const char *expected_content_type, int expect_asn1,
  76. size_t max_resp_len, int timeout, int keep_alive);
  77. BIO *OSSL_HTTP_exchange(OSSL_HTTP_REQ_CTX *rctx, char **redirection_url);
  78. BIO *OSSL_HTTP_get(const char *url, const char *proxy, const char *no_proxy,
  79. BIO *bio, BIO *rbio,
  80. OSSL_HTTP_bio_cb_t bio_update_fn, void *arg,
  81. int buf_size, const STACK_OF(CONF_VALUE) *headers,
  82. const char *expected_content_type, int expect_asn1,
  83. size_t max_resp_len, int timeout);
  84. BIO *OSSL_HTTP_transfer(OSSL_HTTP_REQ_CTX **prctx,
  85. const char *server, const char *port,
  86. const char *path, int use_ssl,
  87. const char *proxy, const char *no_proxy,
  88. BIO *bio, BIO *rbio,
  89. OSSL_HTTP_bio_cb_t bio_update_fn, void *arg,
  90. int buf_size, const STACK_OF(CONF_VALUE) *headers,
  91. const char *content_type, BIO *req,
  92. const char *expected_content_type, int expect_asn1,
  93. size_t max_resp_len, int timeout, int keep_alive);
  94. int OSSL_HTTP_close(OSSL_HTTP_REQ_CTX *rctx, int ok);
  95. /* Auxiliary functions */
  96. int OSSL_HTTP_parse_url(const char *url, int *pssl, char **puser, char **phost,
  97. char **pport, int *pport_num,
  98. char **ppath, char **pquery, char **pfrag);
  99. const char *OSSL_HTTP_adapt_proxy(const char *proxy, const char *no_proxy,
  100. const char *server, int use_ssl);
  101. #endif /* !defined(OPENSSL_NO_HTTP) */
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif /* !defined(OPENSSL_HTTP_H) */