Skip to content

Commit adbb614

Browse files
committed
Merge 'Expose some HTTP functionality useful for websocket code' from Povilas Kanapickas
This PR exposes some HTTP functionality that will useful for websocket code. The PR essentially takes two commits from #2552 so that it's easier to review and land the PR. Closes #2579 * https://github.com/scylladb/seastar: http: Make request writing functions public http: Expose connection_factory implementations
2 parents 6f39b89 + 109b041 commit adbb614

File tree

4 files changed

+77
-51
lines changed

4 files changed

+77
-51
lines changed

include/seastar/http/client.hh

+1-20
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <boost/intrusive/list.hpp>
2626
#endif
2727
#include <seastar/net/api.hh>
28+
#include <seastar/http/connection_factory.hh>
2829
#include <seastar/http/reply.hh>
2930
#include <seastar/core/condition-variable.hh>
3031
#include <seastar/core/iostream.hh>
@@ -136,26 +137,6 @@ private:
136137
void shutdown() noexcept;
137138
};
138139

139-
/**
140-
* \brief Factory that provides transport for \ref client
141-
*
142-
* This customization point allows callers provide its own transport for client. The
143-
* client code calls factory when it needs more connections to the server and maintains
144-
* the pool of re-usable sockets internally
145-
*/
146-
147-
class connection_factory {
148-
public:
149-
/**
150-
* \brief Make a \ref connected_socket
151-
*
152-
* The implementations of this method should return ready-to-use socket that will
153-
* be used by \ref client as transport for its http connections
154-
*/
155-
virtual future<connected_socket> make(abort_source*) = 0;
156-
virtual ~connection_factory() {}
157-
};
158-
159140
/**
160141
* \brief Class client wraps communications using HTTP protocol
161142
*
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* This file is open source software, licensed to you under the terms
3+
* of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4+
* distributed with this work for additional information regarding copyright
5+
* ownership. You may not use this file except in compliance with the License.
6+
*
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <seastar/core/seastar.hh>
22+
#include <seastar/net/api.hh>
23+
#include <seastar/net/tls.hh>
24+
25+
namespace seastar::http::experimental {
26+
27+
/**
28+
* \brief Factory that provides transport for \ref client
29+
*
30+
* This customization point allows callers provide its own transport for client. The
31+
* client code calls factory when it needs more connections to the server.
32+
*/
33+
34+
class connection_factory {
35+
public:
36+
/**
37+
* \brief Make a \ref connected_socket
38+
*
39+
* The implementations of this method should return ready-to-use socket that will
40+
* be used by \ref client as transport for its http connections
41+
*/
42+
virtual future<connected_socket> make(abort_source*) = 0;
43+
virtual ~connection_factory() {}
44+
};
45+
46+
class basic_connection_factory : public connection_factory {
47+
socket_address _addr;
48+
public:
49+
explicit basic_connection_factory(socket_address addr)
50+
: _addr(std::move(addr))
51+
{
52+
}
53+
virtual future<connected_socket> make(abort_source* as) override {
54+
return seastar::connect(_addr, {}, transport::TCP);
55+
}
56+
};
57+
58+
class tls_connection_factory : public connection_factory {
59+
socket_address _addr;
60+
shared_ptr<tls::certificate_credentials> _creds;
61+
sstring _host;
62+
public:
63+
tls_connection_factory(socket_address addr, shared_ptr<tls::certificate_credentials> creds, sstring host)
64+
: _addr(std::move(addr))
65+
, _creds(std::move(creds))
66+
, _host(std::move(host))
67+
{
68+
}
69+
virtual future<connected_socket> make(abort_source* as) override {
70+
return tls::connect(_creds, _addr, tls::tls_options{.server_name = _host});
71+
}
72+
};
73+
74+
}

include/seastar/http/request.hh

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ struct request {
313313
*/
314314
static request make(httpd::operation_type type, sstring host, sstring path);
315315

316-
private:
317-
void add_query_param(std::string_view param);
318316
sstring request_line() const;
319317
future<> write_request_headers(output_stream<char>& out) const;
318+
private:
319+
void add_query_param(std::string_view param);
320320
friend class experimental::connection;
321321
};
322322

src/http/client.cc

-29
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ module seastar;
3535
#include <seastar/core/loop.hh>
3636
#include <seastar/core/when_all.hh>
3737
#include <seastar/core/reactor.hh>
38-
#include <seastar/net/tls.hh>
3938
#include <seastar/http/client.hh>
4039
#include <seastar/http/request.hh>
4140
#include <seastar/http/reply.hh>
@@ -203,39 +202,11 @@ future<> connection::close() {
203202
});
204203
}
205204

206-
class basic_connection_factory : public connection_factory {
207-
socket_address _addr;
208-
public:
209-
explicit basic_connection_factory(socket_address addr)
210-
: _addr(std::move(addr))
211-
{
212-
}
213-
virtual future<connected_socket> make(abort_source* as) override {
214-
return seastar::connect(_addr, {}, transport::TCP);
215-
}
216-
};
217-
218205
client::client(socket_address addr)
219206
: client(std::make_unique<basic_connection_factory>(std::move(addr)))
220207
{
221208
}
222209

223-
class tls_connection_factory : public connection_factory {
224-
socket_address _addr;
225-
shared_ptr<tls::certificate_credentials> _creds;
226-
sstring _host;
227-
public:
228-
tls_connection_factory(socket_address addr, shared_ptr<tls::certificate_credentials> creds, sstring host)
229-
: _addr(std::move(addr))
230-
, _creds(std::move(creds))
231-
, _host(std::move(host))
232-
{
233-
}
234-
virtual future<connected_socket> make(abort_source* as) override {
235-
return tls::connect(_creds, _addr, tls::tls_options{.server_name = _host});
236-
}
237-
};
238-
239210
client::client(socket_address addr, shared_ptr<tls::certificate_credentials> creds, sstring host)
240211
: client(std::make_unique<tls_connection_factory>(std::move(addr), std::move(creds), std::move(host)))
241212
{

0 commit comments

Comments
 (0)