• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 6657874305

26 Oct 2023 05:49PM UTC coverage: 91.694% (+0.07%) from 91.627%
6657874305

push

github

web-flow
Merge pull request #3765 from randombit/fix/asio_compat

Introduce <botan/boost_compat.h> as feature flag

80176 of 87439 relevant lines covered (91.69%)

8602162.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.71
/src/lib/utils/http_util/http_util.h
1
/*
2
* HTTP utilities
3
* (C) 2013 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#ifndef BOTAN_UTILS_URLGET_H_
9
#define BOTAN_UTILS_URLGET_H_
10

11
#include <botan/exceptn.h>
12
#include <botan/types.h>
13
#include <chrono>
14
#include <functional>
15
#include <map>
16
#include <string>
17
#include <vector>
18

19
namespace Botan::HTTP {
20

21
/**
22
* HTTP_Error Exception
23
*/
24
class HTTP_Error final : public Exception {
25
   public:
26
      explicit HTTP_Error(const std::string& msg) : Exception("HTTP error " + msg) {}
×
27

28
      ErrorType error_type() const noexcept override { return ErrorType::HttpError; }
×
29
};
30

31
class Response final {
32
   public:
33
      Response() : m_status_code(0), m_status_message("Uninitialized") {}
1✔
34

35
      Response(unsigned int status_code,
1✔
36
               std::string_view status_message,
37
               const std::vector<uint8_t>& body,
38
               const std::map<std::string, std::string>& headers) :
1✔
39
            m_status_code(status_code), m_status_message(status_message), m_body(body), m_headers(headers) {}
1✔
40

41
      unsigned int status_code() const { return m_status_code; }
1✔
42

43
      const std::vector<uint8_t>& body() const { return m_body; }
×
44

45
      const std::map<std::string, std::string>& headers() const { return m_headers; }
×
46

47
      std::string status_message() const { return m_status_message; }
×
48

49
      void throw_unless_ok() const {
×
50
         if(status_code() != 200) {
×
51
            throw HTTP_Error(status_message());
×
52
         }
53
      }
×
54

55
   private:
56
      unsigned int m_status_code;
57
      std::string m_status_message;
58
      std::vector<uint8_t> m_body;
59
      std::map<std::string, std::string> m_headers;
60
};
61

62
BOTAN_TEST_API std::ostream& operator<<(std::ostream& o, const Response& resp);
63

64
typedef std::function<std::string(std::string_view, std::string_view, std::string_view)> http_exch_fn;
65

66
Response http_sync(const http_exch_fn& fn,
67
                   std::string_view verb,
68
                   std::string_view url,
69
                   std::string_view content_type,
70
                   const std::vector<uint8_t>& body,
71
                   size_t allowable_redirects);
72

73
Response http_sync(std::string_view verb,
74
                   std::string_view url,
75
                   std::string_view content_type,
76
                   const std::vector<uint8_t>& body,
77
                   size_t allowable_redirects,
78
                   std::chrono::milliseconds timeout = std::chrono::milliseconds(3000));
79

80
Response BOTAN_TEST_API GET_sync(std::string_view url,
81
                                 size_t allowable_redirects = 1,
82
                                 std::chrono::milliseconds timeout = std::chrono::milliseconds(3000));
83

84
Response POST_sync(std::string_view url,
85
                   std::string_view content_type,
86
                   const std::vector<uint8_t>& body,
87
                   size_t allowable_redirects = 1,
88
                   std::chrono::milliseconds timeout = std::chrono::milliseconds(3000));
89

90
std::string url_encode(std::string_view url);
91

92
}  // namespace Botan::HTTP
93

94
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc