diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2024-02-23 17:50:38 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2024-02-26 11:52:12 +0300 |
commit | 4a3ec1c7e77e3da09d39ab57048bc6b1a39fb003 (patch) | |
tree | ce74d09943dd33282a8aafeafa805c1583d9cdd4 /libbutl/curl.hxx | |
parent | ea51b01330a96084f1b33cc4fef4d7eec6c8d170 (diff) |
Add read_http_status(), parse_http_status_code(), and read_http_response_line() static functions to curl class
Diffstat (limited to 'libbutl/curl.hxx')
-rw-r--r-- | libbutl/curl.hxx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libbutl/curl.hxx b/libbutl/curl.hxx index cd4ebd0..3fa7890 100644 --- a/libbutl/curl.hxx +++ b/libbutl/curl.hxx @@ -4,6 +4,7 @@ #pragma once #include <string> +#include <cstdint> // uint16_t #include <type_traits> #include <libbutl/path.hxx> @@ -120,6 +121,39 @@ namespace butl const std::string& url, A&&... options); + // Read the HTTP response status from an input stream. + // + // Specifically, read and parse the HTTP status line, by default skip over + // the remaining headers (leaving the stream at the beginning of the + // response body), and return the status code and the reason phrase. Throw + // std::invalid_argument if the status line could not be parsed. Pass + // through the ios::failure exception on the stream error. + // + // Note that if ios::failure is thrown the stream's exception mask may not + // be preserved. + // + struct http_status + { + std::uint16_t code; + std::string reason; + }; + + static http_status + read_http_status (ifdstream&, bool skip_headers = true); + + // Parse and return the HTTP status code. Return 0 if the argument is + // invalid. + // + static std::uint16_t + parse_http_status_code (const std::string&); + + // Read the CRLF-terminated line from an input stream, stripping the + // trailing CRLF. Pass through the ios::failure exception on the stream + // error. + // + static std::string + read_http_response_line (ifdstream&); + private: enum method_proto {ftp_get, ftp_put, http_get, http_post}; using method_proto_options = small_vector<const char*, 2>; |