MySQL 9.1.0
Source Code Documentation
connection.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 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_CONNECTION_H_
27#define ROUTER_SRC_HTTP_INCLUDE_HTTP_CLIENT_CONNECTION_H_
28
29#include <string>
30#include <utility>
31
34#include "http/client/request.h"
35
37
38namespace http {
39namespace client {
40
41template <typename IOLayer>
43 public:
45 using IOBuffer = typename Parent::IOBuffer;
46 using Headers = typename Parent::Headers;
48
49 public:
50 Connection(IOLayer s, base::method::Bitset *allowed_method,
51 ConnectionStatusCallbacks *connection_handler,
52 PayloadCallback *payload_callback, bool use_http2)
53 : Parent::Connection(std::move(s), allowed_method, connection_handler,
54 CNO_CONNECTION_KIND::CNO_CLIENT,
55 use_http2 ? CNO_HTTP2 : CNO_HTTP1),
56 payload_{payload_callback},
57 /* Please note that http11 client doesn't
58 need those settings. */
59 initial_settings_received_{use_http2 ? false : true} {}
60
61 void start() override {
62 Parent::do_net_recv();
63 bool has_data = false;
64 if (!initial_settings_received_) {
65 std::unique_lock<std::mutex> lock(Parent::output_buffer_mutex_);
66
67 for (const auto &buffer : Parent::output_buffers_) {
68 if (buffer.size() > 0) {
69 has_data = true;
70 break;
71 }
72 }
73
74 if (!Parent::output_pending_ && has_data) {
75 Parent::output_pending_ = true;
76 }
77 }
78
79 if (has_data) Parent::do_net_send();
80 }
81
82 public: // override CnoInterface
83 int on_settings() override {
84 if (!initial_settings_received_) {
85 initial_settings_received_ = true;
86 payload_->on_connection_ready();
87 }
88 return 0;
89 }
90
91 int on_cno_message_body([[maybe_unused]] const uint32_t session_id,
92 const char *data, const size_t size) override {
93 payload_->on_input_payload(data, size);
94 return 0;
95 }
96
97 int on_cno_message_tail([[maybe_unused]] const uint32_t session_id,
98 [[maybe_unused]] const cno_tail_t *tail) override {
99 Parent::suspend();
100 payload_->on_input_end();
101 response_received_ = true;
102
103 return 0;
104 }
105
106 bool send(const uint32_t *stream_id_ptr, const int status_code,
107 const std::string &method, const std::string &path,
108 const Headers &headers, const IOBuffer &data) override {
109 Parent::resume();
110 response_received_ = false;
111 return Parent::send(stream_id_ptr, status_code, method, path, headers,
112 data);
113 }
114
115 int on_cno_stream_end([[maybe_unused]] const uint32_t id) override {
116 if (!response_received_) {
117 return 1;
118 }
119 return 0;
120 }
121
122 int on_cno_message_head([[maybe_unused]] const uint32_t session_id,
123 const cno_message_t *msg) override {
124 payload_->on_input_begin(msg->code,
125 std::string{msg->method.data, msg->method.size});
126
127 http::base::Headers input_headers;
128 const auto path = cno::to_string(msg->path);
129 cno::Sequence<const cno_header_t> sequence{msg->headers, msg->headers_len};
130
131 for (const auto &header : sequence) {
132 payload_->on_input_header(cno::to_string(header.name).c_str(),
133 cno::to_string(header.value).c_str());
134 }
135
136 return 0;
137 }
138
139 void on_output_buffer_empty() override { payload_->on_output_end_payload(); }
140
141 public:
144 bool response_received_{false};
145};
146
147} // namespace client
148} // namespace http
149
150#endif // ROUTER_SRC_HTTP_INCLUDE_HTTP_CLIENT_CONNECTION_H_
Definition: connection_status_callbacks.h:35
Definition: connection.h:103
headers of a HTTP response/request.
Definition: headers.h:43
Definition: io_buffer.h:41
Definition: connection.h:42
bool send(const uint32_t *stream_id_ptr, const int status_code, const std::string &method, const std::string &path, const Headers &headers, const IOBuffer &data) override
Definition: connection.h:106
void start() override
Definition: connection.h:61
int on_cno_message_tail(const uint32_t session_id, const cno_tail_t *tail) override
Definition: connection.h:97
Connection(IOLayer s, base::method::Bitset *allowed_method, ConnectionStatusCallbacks *connection_handler, PayloadCallback *payload_callback, bool use_http2)
Definition: connection.h:50
int on_cno_message_body(const uint32_t session_id, const char *data, const size_t size) override
Definition: connection.h:91
PayloadCallback * payload_
Definition: connection.h:142
void on_output_buffer_empty() override
Definition: connection.h:139
int on_settings() override
Definition: connection.h:83
int on_cno_message_head(const uint32_t session_id, const cno_message_t *msg) override
Definition: connection.h:122
int on_cno_stream_end(const uint32_t id) override
Definition: connection.h:115
bool initial_settings_received_
Definition: connection.h:143
Definition: payload_callback.h:36
Definition: buffer_sequence.h:39
size_t size() const noexcept
Definition: buffer.h:120
#define HTTP_CLIENT_EXPORT
Definition: http_client_export.h:15
mysql_service_status_t send(const char *tag, const unsigned char *data, const size_t data_length) noexcept
Definition: message_service.cc:33
static char * path
Definition: mysqldump.cc:149
std::bitset< Pos::_LAST+1 > Bitset
Definition: method.h:57
Request::IOBuffer IOBuffer
Definition: request.cc:33
Request::Headers Headers
Definition: request.cc:35
std::string to_string(const T &str)
Convert CNO buffers to strings.
Definition: string.h:42
Definition: connection.h:56
size_t size(const char *const c)
Definition: base64.h:46
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
Definition: gcs_xcom_synode.h:64
static std::mutex lock
Definition: net_ns.cc:56
long long sequence(UDF_INIT *initid, UDF_ARGS *args, unsigned char *, unsigned char *)
Definition: udf_example.cc:568