proxygen
EchoHandler.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 "EchoHandler.h"
11 
14 
15 #include "EchoStats.h"
16 
17 using namespace proxygen;
18 
19 namespace EchoService {
20 
21 EchoHandler::EchoHandler(EchoStats* stats): stats_(stats) {
22 }
23 
24 void EchoHandler::onRequest(std::unique_ptr<HTTPMessage> /*headers*/) noexcept {
26 }
27 
28 void EchoHandler::onBody(std::unique_ptr<folly::IOBuf> body) noexcept {
29  if (body_) {
30  body_->prependChain(std::move(body));
31  } else {
32  body_ = std::move(body);
33  }
34 }
35 
38  .status(200, "OK")
39  .header("Request-Number",
40  folly::to<std::string>(stats_->getRequestCount()))
42  .sendWithEOM();
43 }
44 
46  // handler doesn't support upgrades
47 }
48 
50  delete this;
51 }
52 
53 void EchoHandler::onError(ProxygenError /*err*/) noexcept { delete this; }
54 }
ResponseBuilder & status(uint16_t code, const std::string &message)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void onBody(std::unique_ptr< folly::IOBuf > body) noexceptoverride
Definition: EchoHandler.cpp:28
ResponseBuilder & body(std::unique_ptr< folly::IOBuf > bodyIn)
requires E e noexcept(noexcept(s.error(std::move(e))))
virtual void recordRequest()
Definition: EchoStats.h:29
std::unique_ptr< folly::IOBuf > body_
Definition: EchoHandler.h:43
void requestComplete() noexceptoverride
Definition: EchoHandler.cpp:49
void onUpgrade(proxygen::UpgradeProtocol proto) noexceptoverride
Definition: EchoHandler.cpp:45
EchoStats *const stats_
Definition: EchoHandler.h:41
ResponseBuilder & header(const std::string &headerIn, const T &value)
void onEOM() noexceptoverride
Definition: EchoHandler.cpp:36
virtual uint64_t getRequestCount()
Definition: EchoStats.h:33
void onError(proxygen::ProxygenError err) noexceptoverride
Definition: EchoHandler.cpp:53
void onRequest(std::unique_ptr< proxygen::HTTPMessage > headers) noexceptoverride
Definition: EchoHandler.cpp:24
ResponseHandler * downstream_