proxygen
SimStreamingCallback.h
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 #pragma once
11 
12 #include <folly/Expected.h>
17 
18 namespace proxygen { namespace compress {
20  public:
22  std::function<void(std::chrono::milliseconds)> cb,
23  bool isP=false)
24  : requestIndex(index), headersCompleteCb(cb), isPublic(isP) {
25  }
26 
28  std::swap(msg, goner.msg);
29  requestIndex = goner.requestIndex;
30  seqn = goner.seqn;
31  error = goner.error;
32  std::swap(headersCompleteCb, goner.headersCompleteCb);
33  }
34 
36  const folly::fbstring& value) override {
37  if (name[0] == ':' && !isPublic) {
38  if (name == headers::kMethod) {
39  msg.setMethod(value);
40  } else if (name == headers::kScheme) {
41  if (value == headers::kHttps) {
42  msg.setSecure(true);
43  }
44  } else if (name == headers::kAuthority) {
46  } else if (name == headers::kPath) {
47  msg.setURL(value.toStdString());
48  } else {
49  DCHECK(false) << "Bad header name=" << name << " value=" << value;
50  }
51  } else {
52  msg.getHeaders().add(name.toStdString(), value.toStdString());
53  }
54  }
55 
57  auto combinedCookie = msg.getHeaders().combine(HTTP_HEADER_COOKIE, "; ");
58  if (!combinedCookie.empty()) {
59  msg.getHeaders().set(HTTP_HEADER_COOKIE, combinedCookie);
60  }
61  std::chrono::milliseconds holDelay(0);
63  holDelay = millisecondsSince(holStart);
64  }
65  complete = true;
66  if (headersCompleteCb) {
67  headersCompleteCb(holDelay);
68  }
69  }
70 
71  void onDecodeError(HPACK::DecodeError decodeError) override {
72  error = decodeError;
73  DCHECK(false) << "Unexpected error in simulator";
74  }
75 
78  return &msg;
79  } else {
81  }
82  }
83 
85  if (!complete) {
87  }
88  }
89 
90  // Global index (across all domains)
92  // Per domain request sequence number
96  std::function<void(std::chrono::milliseconds)> headersCompleteCb;
98  bool complete{false};
99  bool isPublic{false};
100 };
101 
102 }} // namespace proxygen::compress
void onHeader(const folly::fbstring &name, const folly::fbstring &value) override
SimStreamingCallback(SimStreamingCallback &&goner) noexcept
requires E e noexcept(noexcept(s.error(std::move(e))))
std::string combine(const T &header, const std::string &separator=COMBINE_SEPARATOR) const
Definition: HTTPHeaders.h:382
const std::string kScheme
const char * name
Definition: http_parser.c:437
void set(folly::StringPiece name, const std::string &value)
Definition: HTTPHeaders.h:119
void setSecure(bool secure)
Definition: HTTPMessage.h:534
ParseURL setURL(T &&url)
Definition: HTTPMessage.h:183
constexpr Unexpected< typename std::decay< Error >::type > makeUnexpected(Error &&)
Definition: Expected.h:785
folly::Expected< proxygen::HTTPMessage *, HPACK::DecodeError > getResult()
std::basic_string< E, T, A > toStdString() const
Definition: FBString.h:1227
std::function< void(std::chrono::milliseconds)> headersCompleteCb
static const char *const value
Definition: Conv.cpp:50
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
void onHeadersComplete(HTTPHeaderSize) override
void setMethod(HTTPMethod method)
SimStreamingCallback(uint16_t index, std::function< void(std::chrono::milliseconds)> cb, bool isP=false)
SteadyClock::time_point TimePoint
Definition: Time.h:25
std::chrono::milliseconds millisecondsSince(std::chrono::time_point< ClockType > t)
Definition: Time.h:101
static const std::chrono::time_point< ClockType > & getZeroTimePoint()
Definition: Time.h:178
std::chrono::time_point< ClockType > getCurrentTime()
Definition: Time.h:41
const std::string kPath
void onDecodeError(HPACK::DecodeError decodeError) override
void add(folly::StringPiece name, folly::StringPiece value)
Definition: HTTPHeaders.cpp:52
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414
const std::string kAuthority
const std::string kMethod
const std::string kHttps