proxygen
HTTPChecks.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  */
11 
13 
14 namespace proxygen {
15 
17  std::unique_ptr<HTTPMessage> msg) {
18 
19  if (msg->isRequest() && (RFC2616::isRequestBodyAllowed(msg->getMethod())
21  RFC2616::bodyImplied(msg->getHeaders())) {
22  HTTPException ex(
23  HTTPException::Direction::INGRESS, "RFC2616: Request Body Not Allowed");
25  // setting the status code means that the error is at the HTTP layer and
26  // that parsing succeeded.
27  ex.setHttpStatusCode(400);
28  callback_->onError(stream, ex, true);
29  return;
30  }
31 
32  callback_->onHeadersComplete(stream, std::move(msg));
33 }
34 
36  StreamID stream,
37  const HTTPMessage& msg,
38  bool eom,
39  HTTPHeaderSize* sizeOut) {
40  if (msg.isRequest() && RFC2616::bodyImplied(msg.getHeaders())) {
43  // We could also add a "strict" mode that disallows sending body on GET
44  // requests here too.
45  }
46 
47  call_->generateHeader(writeBuf, stream, msg, eom, sizeOut);
48 }
49 
50 }
void setHttpStatusCode(uint32_t statusCode)
Definition: HTTPException.h:86
bool bodyImplied(const HTTPHeaders &headers)
Definition: RFC2616.cpp:59
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void setProxygenError(ProxygenError proxygenError)
Definition: Exception.h:46
void writeBuf(const Buf &buf, folly::io::Appender &out)
BodyAllowed isRequestBodyAllowed(folly::Optional< HTTPMethod > method)
Definition: RFC2616.cpp:43
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
void onHeadersComplete(StreamID stream, std::unique_ptr< HTTPMessage > msg) override
Definition: HTTPChecks.cpp:16
bool isRequest() const
Definition: HTTPMessage.h:661
folly::Optional< HTTPMethod > getMethod() const
void generateHeader(folly::IOBufQueue &writeBuf, StreamID stream, const HTTPMessage &msg, bool eom, HTTPHeaderSize *sizeOut) override
Definition: HTTPChecks.cpp:35