MySQL 8.4.2
Source Code Documentation
request.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have include d with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef ROUTER_SRC_HTTP_INCLUDE_HTTP_CLIENT_REQUEST_H_
26#define ROUTER_SRC_HTTP_INCLUDE_HTTP_CLIENT_REQUEST_H_
27
28#include <memory>
29#include <string>
30#include <utility>
31
32#include "http/base/request.h"
33
35
36namespace http {
37namespace client {
38
40 public:
47
48 public:
49 explicit Request(const Uri &uri, MethodType method = http::base::method::Get)
50 : holder_{std::make_unique<Holder>(uri, method)} {}
51
52 Request() : Request(Uri{"/"}, http::base::method::Get) {}
53 Request(Request &&);
54 ~Request() override;
55
56 // Informations that we received from other side
57 // In case of:
58 // * server, they are Request data
59 // * client, they are Response data
60 const Headers &get_input_headers() const override;
61 IOBuffer &get_input_buffer() const override;
62 const std::string &get_input_body() const override;
63
64 Headers &get_output_headers() override;
65 IOBuffer &get_output_buffer() override;
66
67 StatusType get_response_code() const override;
68 std::string get_response_code_line() const;
69
70 void set_method(MethodType) override;
71 MethodType get_method() const override;
72
73 const Uri &get_uri() const override;
74 void set_uri(const Uri &uri) override;
75 void set_uri(Uri &&uri) override;
76
77 ConnectionInterface *get_connection() const override;
78
79 operator bool() const {
80 if (!holder_) return false;
81 return (holder_->status >= 0);
82 }
83
84 std::string error_msg() const {
85 if (*this) return {};
86
87 return holder_->status_text;
88 }
89
90 private:
91 friend class Client;
92
93 class Holder {
94 public:
95 Holder(const Uri &u, MethodType m) : uri{u}, method{m} {}
96
103 ConnectionInterface *connection_interface{nullptr};
104 // Following two variables, may hold either HTTP status
105 // or error codes with text message.
107 std::string status_text;
108 };
109
110 std::unique_ptr<Holder> holder_;
111};
112
113} // namespace client
114} // namespace http
115
116#endif // ROUTER_SRC_HTTP_INCLUDE_HTTP_CLIENT_REQUEST_H_
Definition: connection_interface.h:41
headers of a HTTP response/request.
Definition: headers.h:43
Definition: io_buffer.h:41
Definition: request.h:44
http::base::method::key_type MethodType
Definition: request.h:49
http::base::status_code::key_type StatusType
Definition: request.h:50
Definition: uri.h:38
Definition: client.h:47
Definition: request.h:93
IOBuffer buffer_output
Definition: request.h:100
Headers headers_output
Definition: request.h:98
IOBuffer buffer_input
Definition: request.h:99
std::string status_text
Definition: request.h:107
Headers headers_input
Definition: request.h:97
MethodType method
Definition: request.h:102
Uri uri
Definition: request.h:101
Holder(const Uri &u, MethodType m)
Definition: request.h:95
Definition: request.h:39
std::string error_msg() const
Definition: request.h:84
std::unique_ptr< Holder > holder_
Definition: request.h:110
Request(const Uri &uri, MethodType method=http::base::method::Get)
Definition: request.h:49
Request()
Definition: request.h:52
static int get_connection(MEM_ROOT *mem_root, FEDERATED_SHARE *share)
Definition: ha_federated.cc:608
#define HTTP_CLIENT_EXPORT
Definition: http_client_export.h:15
constexpr pos_type Get
Definition: method.h:43
constexpr key_type Get
Definition: method.h:60
int key_type
Definition: method.h:38
int key_type
Definition: status_code.h:36
Request::ConnectionInterface ConnectionInterface
Definition: request.cc:38
Request::IOBuffer IOBuffer
Definition: request.cc:33
Request::Headers Headers
Definition: request.cc:35
Request::Uri Uri
Definition: request.cc:37
Definition: connection.h:56
Unique_ptr< T, std::nullptr_t > make_unique(size_t size)
In-place constructs a new unique pointer with no specific allocator and with array type T.
Definition: gcs_xcom_synode.h:64
required uint32 status
Definition: replication_asynchronous_connection_failover.proto:61
RestClient::Request Request
Definition: rest_client.cc:29