http_version.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef CPR_HTTP_VERSION_H
  2. #define CPR_HTTP_VERSION_H
  3. #include <curl/curlver.h>
  4. namespace cpr {
  5. enum class HttpVersionCode {
  6. /**
  7. * Let libcurl decide which version is the best.
  8. **/
  9. VERSION_NONE,
  10. /**
  11. * Enforce HTTP 1.0 requests.
  12. **/
  13. VERSION_1_0,
  14. /**
  15. * Enforce HTTP 1.1 requests.
  16. **/
  17. VERSION_1_1,
  18. #if LIBCURL_VERSION_NUM >= 0x072100 // 7.33.0
  19. /**
  20. * Attempt HTTP 2.0 requests.
  21. * Fallback to HTTP 1.1 if negotiation fails.
  22. **/
  23. VERSION_2_0,
  24. #endif
  25. #if LIBCURL_VERSION_NUM >= 0x072F00 // 7.47.0
  26. /**
  27. * Attempt HTTP 2.0 for HTTPS requests only.
  28. * Fallback to HTTP 1.1 if negotiation fails.
  29. * HTTP 1.1 will be used for HTTP connections.
  30. **/
  31. VERSION_2_0_TLS,
  32. #endif
  33. #if LIBCURL_VERSION_NUM >= 0x073100 // 7.49.0
  34. /**
  35. * Start HTTP 2.0 for HTTP requests.
  36. * Requires prior knowledge that the server supports HTTP 2.0.
  37. * For HTTPS requests we will negotiate the protocol version in the TLS handshake.
  38. **/
  39. VERSION_2_0_PRIOR_KNOWLEDGE,
  40. #endif
  41. #if LIBCURL_VERSION_NUM >= 0x074200 // 7.66.0
  42. /**
  43. * Attempt HTTP 3.0 requests.
  44. * Requires prior knowledge that the server supports HTTP 3.0 since there is no gracefully downgrade.
  45. * Fallback to HTTP 1.1 if negotiation fails.
  46. **/
  47. VERSION_3_0
  48. #endif
  49. };
  50. class HttpVersion {
  51. public:
  52. /**
  53. * The HTTP version that should be used by libcurl when initiating a HTTP(S) connection.
  54. * Default: HttpVersionCode::VERSION_NONE
  55. **/
  56. HttpVersionCode code = HttpVersionCode::VERSION_NONE;
  57. HttpVersion() = default;
  58. explicit HttpVersion(HttpVersionCode _code) : code(_code) {}
  59. };
  60. } // namespace cpr
  61. #endif