Repository navigation
Expand file tree
/
Copy pathHTTPServerAcceptor.cpp
More file actions
92 lines (74 loc) · 2.55 KB
/
Copy pathHTTPServerAcceptor.cpp
File metadata and controls
92 lines (74 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include "proxygen/httpserver/HTTPServerAcceptor.h"
#include "proxygen/httpserver/RequestHandlerAdaptor.h"
#include "proxygen/httpserver/RequestHandlerFactory.h"
#include "proxygen/lib/http/codec/HTTP1xCodec.h"
#include "proxygen/lib/http/session/HTTPDownstreamSession.h"
using folly::SocketAddress;
namespace proxygen {
AcceptorConfiguration HTTPServerAcceptor::makeConfig(
const HTTPServer::IPConfig& ipConfig,
const HTTPServerOptions& opts) {
AcceptorConfiguration conf;
conf.bindAddress = ipConfig.address;
conf.connectionIdleTimeout = opts.idleTimeout;
conf.transactionIdleTimeout = opts.idleTimeout;
if (ipConfig.protocol == HTTPServer::Protocol::SPDY) {
conf.plaintextProtocol = "spdy/3.1";
}
conf.sslContextConfigs = ipConfig.sslConfigs;
return conf;
}
std::unique_ptr<HTTPServerAcceptor> HTTPServerAcceptor::make(
const AcceptorConfiguration& conf,
const HTTPServerOptions& opts) {
// Create a copy of the filter chain in reverse order since we need to create
// Handlers in that order.
std::vector<RequestHandlerFactory*> handlerFactories;
for (auto& f: opts.handlerFactories) {
handlerFactories.push_back(f.get());
}
std::reverse(handlerFactories.begin(), handlerFactories.end());
return std::unique_ptr<HTTPServerAcceptor>(
new HTTPServerAcceptor(conf, handlerFactories));
}
HTTPServerAcceptor::HTTPServerAcceptor(
const AcceptorConfiguration& conf,
std::vector<RequestHandlerFactory*> handlerFactories)
: HTTPSessionAcceptor(conf),
handlerFactories_(handlerFactories) {
}
void HTTPServerAcceptor::setCompletionCallback(std::function<void()> f) {
completionCallback_ = f;
}
HTTPServerAcceptor::~HTTPServerAcceptor() {
}
HTTPTransactionHandler* HTTPServerAcceptor::newHandler(
HTTPTransaction& txn,
HTTPMessage* msg) noexcept {
SocketAddress clientAddr, vipAddr;
txn.getPeerAddress(clientAddr);
txn.getLocalAddress(vipAddr);
msg->setClientAddress(clientAddr);
msg->setDstAddress(vipAddr);
// Create filters chain
RequestHandler* h = nullptr;
for (auto& factory: handlerFactories_) {
h = factory->onRequest(h, msg);
}
return new RequestHandlerAdaptor(h);
}
void HTTPServerAcceptor::onConnectionsDrained() {
if (completionCallback_) {
completionCallback_();
}
}
}