25
25
26
26
namespace fs = boost::filesystem;
27
27
28
- using namespace facebook ::presto;
29
- using namespace facebook ::velox;
30
- using namespace facebook ::velox::memory;
31
-
32
28
std::string getCertsPath (const std::string& fileName) {
33
29
std::string currentPath = fs::current_path ().c_str ();
34
30
if (boost::algorithm::ends_with (currentPath, " fbcode" )) {
@@ -65,7 +61,8 @@ inline folly::SSLContextPtr makeSslContext() {
65
61
66
62
class HttpServerWrapper {
67
63
public:
68
- explicit HttpServerWrapper (std::unique_ptr<http::HttpServer> server)
64
+ explicit HttpServerWrapper (
65
+ std::unique_ptr<facebook::presto::http::HttpServer> server)
69
66
: server_(std::move(server)) {}
70
67
71
68
~HttpServerWrapper () {
@@ -100,7 +97,7 @@ class HttpServerWrapper {
100
97
}
101
98
102
99
private:
103
- std::unique_ptr<http::HttpServer> server_;
100
+ std::unique_ptr<facebook::presto:: http::HttpServer> server_;
104
101
std::unique_ptr<std::thread> serverThread_;
105
102
folly::Promise<folly::SocketAddress> promise_;
106
103
std::vector<std::unique_ptr<proxygen::RequestHandlerFactory>> filters_ = {};
@@ -136,15 +133,19 @@ void ping(
136
133
proxygen::HTTPMessage* /* message*/ ,
137
134
std::vector<std::unique_ptr<folly::IOBuf>>& /* body*/ ,
138
135
proxygen::ResponseHandler* downstream) {
139
- proxygen::ResponseBuilder (downstream).status (http::kHttpOk , " " ).sendWithEOM ();
136
+ proxygen::ResponseBuilder (downstream)
137
+ .status (facebook::presto::http::kHttpOk , " " )
138
+ .sendWithEOM ();
140
139
}
141
140
142
141
void blackhole (
143
142
proxygen::HTTPMessage* /* message*/ ,
144
143
std::vector<std::unique_ptr<folly::IOBuf>>& /* body*/ ,
145
144
proxygen::ResponseHandler* downstream) {}
146
145
147
- std::string bodyAsString (http::HttpResponse& response, MemoryPool* pool) {
146
+ std::string bodyAsString (
147
+ facebook::presto::http::HttpResponse& response,
148
+ facebook::velox::memory::MemoryPool* pool) {
148
149
EXPECT_FALSE (response.hasError ());
149
150
std::ostringstream oss;
150
151
auto iobufs = response.consumeBody ();
@@ -170,15 +171,15 @@ void echo(
170
171
proxygen::ResponseHandler* downstream) {
171
172
if (body.empty ()) {
172
173
proxygen::ResponseBuilder (downstream)
173
- .status (http::kHttpOk , " " )
174
+ .status (facebook::presto:: http::kHttpOk , " " )
174
175
.body (folly::IOBuf::wrapBuffer (
175
176
message->getURL ().c_str (), message->getURL ().size ()))
176
177
.sendWithEOM ();
177
178
return ;
178
179
}
179
180
180
181
proxygen::ResponseBuilder (downstream)
181
- .status (http::kHttpOk , " " )
182
+ .status (facebook::presto:: http::kHttpOk , " " )
182
183
.header (proxygen::HTTP_HEADER_CONTENT_TYPE, " text/plain" )
183
184
.body (toString (body))
184
185
.sendWithEOM ();
@@ -196,14 +197,14 @@ class HttpClientFactory {
196
197
eventBaseThread_->join ();
197
198
}
198
199
199
- std::shared_ptr<http::HttpClient> newClient (
200
+ std::shared_ptr<facebook::presto:: http::HttpClient> newClient (
200
201
const folly::SocketAddress& address,
201
202
const std::chrono::milliseconds& transactionTimeout,
202
203
const std::chrono::milliseconds& connectTimeout,
203
204
bool useHttps,
204
- std::shared_ptr<MemoryPool> pool,
205
+ std::shared_ptr<facebook::velox::memory:: MemoryPool> pool,
205
206
std::function<void (int )>&& reportOnBodyStatsFunc = nullptr) {
206
- return std::make_shared<http::HttpClient>(
207
+ return std::make_shared<facebook::presto:: http::HttpClient>(
207
208
eventBase_.get (),
208
209
nullptr ,
209
210
proxygen::Endpoint (
@@ -221,32 +222,33 @@ class HttpClientFactory {
221
222
std::unique_ptr<std::thread> eventBaseThread_;
222
223
};
223
224
224
- folly::SemiFuture<std::unique_ptr<http::HttpResponse>> sendGet (
225
- http::HttpClient* client,
225
+ folly::SemiFuture<std::unique_ptr<facebook::presto::http::HttpResponse>>
226
+ sendGet (
227
+ facebook::presto::http::HttpClient* client,
226
228
const std::string& url,
227
229
const uint64_t sendDelay = 0 ,
228
230
const std::string body = " " ) {
229
- return http::RequestBuilder ()
231
+ return facebook::presto:: http::RequestBuilder ()
230
232
.method (proxygen::HTTPMethod::GET)
231
233
.url (url)
232
234
.send (client, body, sendDelay);
233
235
}
234
236
235
- static std::unique_ptr<http::HttpServer> getHttpServer (
237
+ static std::unique_ptr<facebook::presto:: http::HttpServer> getHttpServer (
236
238
bool useHttps,
237
239
const std::shared_ptr<folly::IOThreadPoolExecutor>& httpIOExecutor) {
238
240
if (useHttps) {
239
241
const std::string certPath = getCertsPath (" test_cert1.pem" );
240
242
const std::string keyPath = getCertsPath (" test_key1.pem" );
241
243
const std::string ciphers = " AES128-SHA,AES128-SHA256,AES256-GCM-SHA384" ;
242
- auto httpsConfig = std::make_unique<http::HttpsConfig>(
244
+ auto httpsConfig = std::make_unique<facebook::presto:: http::HttpsConfig>(
243
245
folly::SocketAddress (" 127.0.0.1" , 0 ), certPath, keyPath, ciphers);
244
- return std::make_unique<http::HttpServer>(
246
+ return std::make_unique<facebook::presto:: http::HttpServer>(
245
247
httpIOExecutor, nullptr , std::move (httpsConfig));
246
248
} else {
247
- return std::make_unique<http::HttpServer>(
249
+ return std::make_unique<facebook::presto:: http::HttpServer>(
248
250
httpIOExecutor,
249
- std::make_unique<http::HttpConfig>(
251
+ std::make_unique<facebook::presto:: http::HttpConfig>(
250
252
folly::SocketAddress (" 127.0.0.1" , 0 )),
251
253
nullptr );
252
254
}
@@ -268,17 +270,18 @@ struct AsyncMsgRequestState {
268
270
std::function<void ()> customFunc;
269
271
};
270
272
271
- http::EndpointRequestHandlerFactory asyncMsg (
273
+ facebook::presto:: http::EndpointRequestHandlerFactory asyncMsg (
272
274
std::shared_ptr<AsyncMsgRequestState> request) {
273
275
return [request](
274
276
proxygen::HTTPMessage* /* message */ ,
275
277
const std::vector<std::string>& /* args */ ) {
276
- return new http::CallbackRequestHandler (
278
+ return new facebook::presto:: http::CallbackRequestHandler (
277
279
[request](
278
280
proxygen::HTTPMessage* /* message*/ ,
279
281
const std::vector<std::unique_ptr<folly::IOBuf>>& /* body*/ ,
280
282
proxygen::ResponseHandler* downstream,
281
- std::shared_ptr<http::CallbackRequestHandlerState> handlerState) {
283
+ std::shared_ptr<facebook::presto::http::CallbackRequestHandlerState>
284
+ handlerState) {
282
285
auto [promise, future] = folly::makePromiseContract<std::string>();
283
286
auto eventBase = folly::EventBaseManager::get ()->getEventBase ();
284
287
auto maxWaitMillis = request->maxWaitMillis ;
@@ -297,7 +300,7 @@ http::EndpointRequestHandlerFactory asyncMsg(
297
300
if (!handlerState->requestExpired ()) {
298
301
request->requestStatus = kStatusValid ;
299
302
proxygen::ResponseBuilder (downstream)
300
- .status (http::kHttpOk , " " )
303
+ .status (facebook::presto:: http::kHttpOk , " " )
301
304
.header (proxygen::HTTP_HEADER_CONTENT_TYPE, " text/plain" )
302
305
.body (msg)
303
306
.sendWithEOM ();
@@ -311,7 +314,9 @@ http::EndpointRequestHandlerFactory asyncMsg(
311
314
if (!handlerState->requestExpired ()) {
312
315
request->requestStatus = kStatusValid ;
313
316
proxygen::ResponseBuilder (downstream)
314
- .status (http::kHttpInternalServerError , " " )
317
+ .status (
318
+ facebook::presto::http::kHttpInternalServerError ,
319
+ " " )
315
320
.header (
316
321
proxygen::HTTP_HEADER_CONTENT_TYPE, " text/plain" )
317
322
.body (e.what ())
0 commit comments