MySQL 8.4.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)
53 : Parent::Connection(std::move(s), allowed_method, connection_handler,
54 CNO_CONNECTION_KIND::CNO_CLIENT),
55 payload_{payload_callback} {}
56
57 public: // override CnoInterface
58 int on_cno_message_body([[maybe_unused]] const uint32_t session_id,
59 const char *data, const size_t size) override {
60 payload_->on_input_payload(data, size);
61 return 0;
62 }
63
64 int on_cno_message_tail([[maybe_unused]] const uint32_t session_id,
65 [[maybe_unused]] const cno_tail_t *tail) override {
66 Parent::suspend();
67 payload_->on_input_end();
68
69 return 0;
70 }
71
72 bool send(const uint32_t *stream_id_ptr, const int status_code,
73 const std::string &method, const std::string &path,
74 const Headers &headers, const IOBuffer &data) override {
75 Parent::resume();
76 return Parent::send(stream_id_ptr, status_code, method, path, headers,
77 data);
78 }
79
80 int on_cno_stream_end([[maybe_unused]] const uint32_t id) override {
81 return 0;
82 }
83
84 int on_cno_message_head([[maybe_unused]] const uint32_t session_id,
85 const cno_message_t *msg) override {
86 payload_->on_input_begin(msg->code,
87 std::string{msg->method.data, msg->method.size});
88
89 http::base::Headers input_headers;
90 const auto path = cno::to_string(msg->path);
91 cno::Sequence<const cno_header_t> sequence{msg->headers, msg->headers_len};
92
93 for (const auto &header : sequence) {
94 payload_->on_input_header(cno::to_string(header.name).c_str(),
95 cno::to_string(header.value).c_str());
96 }
97
98 return 0;
99 }
100
101 void on_output_buffer_empty() override { payload_->on_output_end_payload(); }
102
103 public:
105};
106
107} // namespace client
108} // namespace http
109
110#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:72
int on_cno_message_tail(const uint32_t session_id, const cno_tail_t *tail) override
Definition: connection.h:64
int on_cno_message_body(const uint32_t session_id, const char *data, const size_t size) override
Definition: connection.h:58
PayloadCallback * payload_
Definition: connection.h:104
void on_output_buffer_empty() override
Definition: connection.h:101
Connection(IOLayer s, base::method::Bitset *allowed_method, ConnectionStatusCallbacks *connection_handler, PayloadCallback *payload_callback)
Definition: connection.h:50
int on_cno_message_head(const uint32_t session_id, const cno_message_t *msg) override
Definition: connection.h:84
int on_cno_stream_end(const uint32_t id) override
Definition: connection.h:80
Definition: payload_callback.h:36
Definition: buffer_sequence.h:39
#define HTTP_CLIENT_EXPORT
Definition: http_client_export.h:40
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
Definition: gcs_xcom_synode.h:64
long long sequence(UDF_INIT *initid, UDF_ARGS *args, unsigned char *, unsigned char *)
Definition: udf_example.cc:568