MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
request.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2024, 2025, 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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_SRC_HTTP_INCLUDE_HTTP_CLIENT_REQUEST_H_
27#define ROUTER_SRC_HTTP_INCLUDE_HTTP_CLIENT_REQUEST_H_
28
29#include <memory>
30#include <string>
31#include <utility>
32
33#include "http/base/request.h"
34
36
37namespace http {
38namespace client {
39
41 public:
48
49 public:
50 explicit Request(const Uri &uri, MethodType method = http::base::method::Get)
51 : holder_{std::make_unique<Holder>(uri, method)} {}
52
53 Request() : Request(Uri{"/"}, http::base::method::Get) {}
54 Request(Request &&);
55 ~Request() override;
56
57 // Informations that we received from other side
58 // In case of:
59 // * server, they are Request data
60 // * client, they are Response data
61 const Headers &get_input_headers() const override;
62 IOBuffer &get_input_buffer() const override;
63 const std::string &get_input_body() const override;
64
65 Headers &get_output_headers() override;
66 IOBuffer &get_output_buffer() override;
67
68 StatusType get_response_code() const override;
69 std::string get_response_code_line() const;
70
71 void set_method(MethodType) override;
72 MethodType get_method() const override;
73
74 const Uri &get_uri() const override;
75 void set_uri(const Uri &uri) override;
76 void set_uri(Uri &&uri) override;
77
78 ConnectionInterface *get_connection() const override;
79
80 operator bool() const {
81 if (!holder_) return false;
82 return (holder_->status >= 0);
83 }
84
85 std::string error_msg() const {
86 if (*this) return {};
87
88 return holder_->status_text;
89 }
90
91 private:
92 friend class Client;
93
94 class Holder {
95 public:
96 Holder(const Uri &u, MethodType m) : uri{u}, method{m} {}
97
104 ConnectionInterface *connection_interface{nullptr};
105 // Following two variables, may hold either HTTP status
106 // or error codes with text message.
108 std::string status_text;
109 };
110
111 std::unique_ptr<Holder> holder_;
112};
113
114} // namespace client
115} // namespace http
116
117#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:40
Definition: client.h:47
Definition: request.h:94
IOBuffer buffer_output
Definition: request.h:101
Headers headers_output
Definition: request.h:99
IOBuffer buffer_input
Definition: request.h:100
std::string status_text
Definition: request.h:108
Headers headers_input
Definition: request.h:98
MethodType method
Definition: request.h:103
Uri uri
Definition: request.h:102
Holder(const Uri &u, MethodType m)
Definition: request.h:96
Definition: request.h:40
std::string error_msg() const
Definition: request.h:85
std::unique_ptr< Holder > holder_
Definition: request.h:111
Request(const Uri &uri, MethodType method=http::base::method::Get)
Definition: request.h:50
Request()
Definition: request.h:53
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:37
Request::IOBuffer IOBuffer
Definition: request.cc:32
Request::Headers Headers
Definition: request.cc:34
Request::Uri Uri
Definition: request.cc:36
Definition: connection.h:55
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