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

randombit / botan / 5111374265

29 May 2023 11:19AM UTC coverage: 92.227% (+0.5%) from 91.723%
5111374265

push

github

randombit
Next release will be 3.1.0. Update release notes

75588 of 81959 relevant lines covered (92.23%)

11886470.91 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 {
20

21
namespace HTTP {
22

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

30
      ErrorType error_type() const noexcept override { return ErrorType::HttpError; }
×
31
};
32

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

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

43
      unsigned int status_code() const { return m_status_code; }
1✔
44

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

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

49
      std::string status_message() const { return m_status_message; }
×
50

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

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

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

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

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

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

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

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

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

93
}  // namespace HTTP
94

95
}  // namespace Botan
96

97
#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