proxygen
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
HTTPDirectResponseHandler.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2015-present, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
*/
10
#include <
proxygen/lib/http/session/HTTPDirectResponseHandler.h
>
11
12
#include <
folly/Conv.h
>
13
#include <
proxygen/lib/http/session/HTTPErrorPage.h
>
14
15
using
folly::IOBuf
;
16
using
std::string
;
17
using
std::unique_ptr;
18
19
namespace
proxygen
{
20
21
HTTPDirectResponseHandler::HTTPDirectResponseHandler
(
22
unsigned
statusCode
,
const
std::string
& statusMsg,
23
const
HTTPErrorPage
* errorPage):
24
txn_(
nullptr
),
25
errorPage_(errorPage),
26
statusMessage_(statusMsg),
27
statusCode_(statusCode),
28
headersSent_(false),
29
eomSent_(false),
30
forceConnectionClose_(true) {
31
}
32
33
HTTPDirectResponseHandler::~HTTPDirectResponseHandler
() {
34
}
35
36
void
37
HTTPDirectResponseHandler::setTransaction
(
HTTPTransaction
* txn)
noexcept
{
38
txn_
= txn;
39
}
40
41
void
42
HTTPDirectResponseHandler::detachTransaction
()
noexcept
{
43
delete
this
;
44
}
45
46
void
HTTPDirectResponseHandler::onHeadersComplete
(
47
std::unique_ptr<HTTPMessage>
/*msg*/
)
noexcept
{
48
VLOG(4) <<
"processing request"
;
49
headersSent_
=
true
;
50
HTTPMessage
response;
51
std::unique_ptr<folly::IOBuf> responseBody;
52
response.
setHTTPVersion
(1, 1);
53
response.
setStatusCode
(
statusCode_
);
54
if
(!
statusMessage_
.empty()) {
55
response.
setStatusMessage
(
statusMessage_
);
56
}
else
{
57
response.
setStatusMessage
(
HTTPMessage::getDefaultReason
(
statusCode_
));
58
}
59
if
(
forceConnectionClose_
) {
60
response.
getHeaders
().
add
(
HTTP_HEADER_CONNECTION
,
"close"
);
61
}
62
if
(
errorPage_
) {
63
HTTPErrorPage::Page
page =
errorPage_
->
generate
(0,
statusCode_
,
64
statusMessage_
,
nullptr
,
empty_string
);
65
VLOG(4) <<
"sending error page with type "
<< page.
contentType
;
66
response.
getHeaders
().
add
(
HTTP_HEADER_CONTENT_TYPE
, page.
contentType
);
67
responseBody =
std::move
(page.
content
);
68
}
69
response.
getHeaders
().
add
(
HTTP_HEADER_CONTENT_LENGTH
, folly::to<string>(
70
responseBody ? responseBody->
computeChainDataLength
() : 0));
71
txn_
->
sendHeaders
(response);
72
if
(responseBody) {
73
txn_
->
sendBody
(
std::move
(responseBody));
74
}
75
}
76
77
void
HTTPDirectResponseHandler::onBody
(unique_ptr<IOBuf>
/*chain*/
)
noexcept
{
78
VLOG(4) <<
"discarding request body"
;
79
}
80
81
void
HTTPDirectResponseHandler::onTrailers
(
82
unique_ptr<HTTPHeaders>
/*trailers*/
)
noexcept
{
83
VLOG(4) <<
"discarding request trailers"
;
84
}
85
86
void
87
HTTPDirectResponseHandler::onEOM
()
noexcept
{
88
eomSent_
=
true
;
89
txn_
->
sendEOM
();
90
}
91
92
void
HTTPDirectResponseHandler::onUpgrade
(
93
UpgradeProtocol
/*protocol*/
)
noexcept
{}
94
95
void
HTTPDirectResponseHandler::onError
(
const
HTTPException
&
error
)
noexcept
{
96
if
(
error
.getDirection() ==
HTTPException::Direction::INGRESS
) {
97
if
(
error
.getProxygenError() ==
kErrorTimeout
) {
98
VLOG(4) <<
"processing ingress timeout"
;
99
if
(!
headersSent_
) {
100
onHeadersComplete
(
nullptr
);
101
}
102
if
(!
eomSent_
) {
103
onEOM
();
104
}
105
}
else
{
106
VLOG(4) <<
"processing ingress error"
;
107
if
(!
headersSent_
) {
108
onHeadersComplete
(
nullptr
);
109
}
110
if
(!
eomSent_
) {
111
onEOM
();
112
}
113
}
114
}
115
}
116
117
}
// proxygen
folly::IOBuf
Definition:
IOBuf.h:221
proxygen::HTTPDirectResponseHandler::errorPage_
const HTTPErrorPage * errorPage_
Definition:
HTTPDirectResponseHandler.h:44
statusCode
spdy::GoawayStatusCode statusCode
Definition:
SPDYCodec.cpp:110
proxygen::HTTPDirectResponseHandler::headersSent_
bool headersSent_
Definition:
HTTPDirectResponseHandler.h:47
proxygen::HTTPDirectResponseHandler::txn_
HTTPTransaction * txn_
Definition:
HTTPDirectResponseHandler.h:43
proxygen::HTTPDirectResponseHandler::onEOM
void onEOM() noexceptoverride
Definition:
HTTPDirectResponseHandler.cpp:87
proxygen::HTTPMessage::setStatusMessage
void setStatusMessage(T &&msg)
Definition:
HTTPMessage.h:242
proxygen::HTTPDirectResponseHandler::~HTTPDirectResponseHandler
~HTTPDirectResponseHandler() override
Definition:
HTTPDirectResponseHandler.cpp:33
proxygen::HTTPErrorPage
Definition:
HTTPErrorPage.h:25
HTTPDirectResponseHandler.h
folly::gen::move
constexpr detail::Map< Move > move
Definition:
Base-inl.h:2567
proxygen::HTTPDirectResponseHandler::statusCode_
unsigned statusCode_
Definition:
HTTPDirectResponseHandler.h:46
proxygen::HTTP_HEADER_CONNECTION
Definition:
HTTPCommonHeaders.h:60
proxygen::HTTPDirectResponseHandler::eomSent_
bool eomSent_
Definition:
HTTPDirectResponseHandler.h:48
proxygen::HTTPErrorPage::Page
Definition:
HTTPErrorPage.h:27
proxygen::HTTPException
Definition:
HTTPException.h:26
proxygen::HTTPErrorPage::Page::contentType
const std::string contentType
Definition:
HTTPErrorPage.h:37
folly::pushmi::__adl::noexcept
requires E e noexcept(noexcept(s.error(std::move(e))))
Definition:
extension_points.h:40
proxygen::UpgradeProtocol
UpgradeProtocol
Definition:
HTTPConstants.h:61
folly::pushmi::operators::error
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition:
error.h:48
nullptr
#define nullptr
Definition:
http_parser.c:41
proxygen::HTTPTransaction
Definition:
HTTPTransaction.h:324
proxygen::HTTP_HEADER_CONTENT_TYPE
Definition:
HTTPCommonHeaders.h:63
proxygen::HTTP_HEADER_CONTENT_LENGTH
Definition:
HTTPCommonHeaders.h:49
proxygen::HTTPDirectResponseHandler::HTTPDirectResponseHandler
HTTPDirectResponseHandler(unsigned statusCode, const std::string &statusMsg, const HTTPErrorPage *errorPage=nullptr)
Definition:
HTTPDirectResponseHandler.cpp:21
proxygen::HTTPException::Direction::INGRESS
HTTPErrorPage.h
proxygen::HTTPTransaction::sendBody
virtual void sendBody(std::unique_ptr< folly::IOBuf > body)
Definition:
HTTPTransaction.cpp:784
proxygen::HTTPDirectResponseHandler::onBody
void onBody(std::unique_ptr< folly::IOBuf > chain) noexceptoverride
Definition:
HTTPDirectResponseHandler.cpp:77
proxygen::HTTPTransaction::sendHeaders
virtual void sendHeaders(const HTTPMessage &headers)
Definition:
HTTPTransaction.cpp:780
proxygen::HTTPMessage::getHeaders
HTTPHeaders & getHeaders()
Definition:
HTTPMessage.h:273
proxygen::kErrorTimeout
Definition:
ProxygenErrorEnum.h:74
proxygen::HTTPDirectResponseHandler::setTransaction
void setTransaction(HTTPTransaction *txn) noexceptoverride
Definition:
HTTPDirectResponseHandler.cpp:37
proxygen::HTTPErrorPage::generate
virtual Page generate(uint64_t requestID, unsigned httpStatusCode, const std::string &reason, std::unique_ptr< folly::IOBuf > body, const std::string &detailReason) const =0
Conv.h
folly::IOBuf::computeChainDataLength
std::size_t computeChainDataLength() const
Definition:
IOBuf.cpp:501
proxygen::HTTPDirectResponseHandler::onHeadersComplete
void onHeadersComplete(std::unique_ptr< HTTPMessage > msg) noexceptoverride
Definition:
HTTPDirectResponseHandler.cpp:46
proxygen::empty_string
const std::string empty_string
Definition:
HTTPHeaders.cpp:23
string
const char * string
Definition:
Conv.cpp:212
proxygen::HTTPDirectResponseHandler::onUpgrade
void onUpgrade(UpgradeProtocol protocol) noexceptoverride
Definition:
HTTPDirectResponseHandler.cpp:92
proxygen::HTTPDirectResponseHandler::statusMessage_
std::string statusMessage_
Definition:
HTTPDirectResponseHandler.h:45
proxygen
Definition:
ExMessageHandler.h:14
proxygen::HTTPMessage::setHTTPVersion
void setHTTPVersion(uint8_t major, uint8_t minor)
Definition:
HTTPMessage.cpp:256
proxygen::HTTPDirectResponseHandler::onError
void onError(const HTTPException &error) noexceptoverride
Definition:
HTTPDirectResponseHandler.cpp:95
proxygen::HTTPHeaders::add
void add(folly::StringPiece name, folly::StringPiece value)
Definition:
HTTPHeaders.cpp:52
proxygen::HTTPMessage
Definition:
HTTPMessage.h:39
proxygen::HTTPMessage::getDefaultReason
static const char * getDefaultReason(uint16_t status)
Definition:
HTTPMessage.cpp:882
proxygen::HTTPErrorPage::Page::content
std::unique_ptr< folly::IOBuf > content
Definition:
HTTPErrorPage.h:38
proxygen::HTTPDirectResponseHandler::forceConnectionClose_
bool forceConnectionClose_
Definition:
HTTPDirectResponseHandler.h:49
proxygen::HTTPDirectResponseHandler::onTrailers
void onTrailers(std::unique_ptr< HTTPHeaders > trailers) noexceptoverride
Definition:
HTTPDirectResponseHandler.cpp:81
proxygen::HTTPTransaction::sendEOM
virtual void sendEOM()
Definition:
HTTPTransaction.cpp:1003
proxygen::HTTPDirectResponseHandler::detachTransaction
void detachTransaction() noexceptoverride
Definition:
HTTPDirectResponseHandler.cpp:42
proxygen::HTTPMessage::setStatusCode
void setStatusCode(uint16_t status)
Definition:
HTTPMessage.cpp:335
proxygen
lib
http
session
HTTPDirectResponseHandler.cpp
Generated by
1.8.11