proxygen
HTTPTransactionEgressSM.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 
12 #include <unordered_map>
13 
14 #include <folly/hash/Hash.h>
15 #include <folly/Indestructible.h>
16 
17 namespace proxygen {
18 
19 std::pair<HTTPTransactionEgressSMData::State, bool>
24  using TransitionTable =
25  std::unordered_map<std::pair<State, Event>, State, folly::Hash>;
26 
27  // +--> ChunkHeaderSent -> ChunkBodySent
28  // | ^ v
29  // | | ChunkTerminatorSent -> TrailersSent
30  // | |__________| | |
31  // | | v
32  // Start -> HeadersSent +----> EOMQueued --> SendingDone
33  // | ^
34  // +------------> RegularBodySent -------+
35 
36  static const folly::Indestructible<TransitionTable> transitions{
37  TransitionTable{
39 
40  // For HTTP sending 100 response, then a regular response
41  {{State::HeadersSent, Event::sendHeaders}, State::HeadersSent},
42 
47 
48  {{State::RegularBodySent, Event::sendBody}, State::RegularBodySent},
49  {{State::RegularBodySent, Event::sendTrailers}, State::TrailersSent},
50  {{State::RegularBodySent, Event::sendEOM}, State::EOMQueued},
51 
53 
54  {{State::ChunkBodySent, Event::sendBody}, State::ChunkBodySent},
57 
59  State::ChunkHeaderSent},
60  {{State::ChunkTerminatorSent, Event::sendTrailers}, State::TrailersSent},
61  {{State::ChunkTerminatorSent, Event::sendEOM}, State::EOMQueued},
62 
63  {{State::TrailersSent, Event::sendEOM}, State::EOMQueued},
64 
66  }
67  };
68 
69  auto const &it = transitions->find(std::make_pair(s, e));
70  if (it == transitions->end()) {
71  return std::make_pair(s, false);
72  }
73 
74  return std::make_pair(it->second, true);
75 }
76 
77 std::ostream& operator<<(std::ostream& os,
79  switch (s) {
81  os << "Start";
82  break;
84  os << "HeadersSent";
85  break;
87  os << "RegularBodySent";
88  break;
90  os << "ChunkHeaderSent";
91  break;
93  os << "ChunkBodySent";
94  break;
96  os << "ChunkTerminatorSent";
97  break;
99  os << "TrailersSent";
100  break;
102  os << "EOMQueued";
103  break;
105  os << "SendingDone";
106  break;
107  }
108 
109  return os;
110 }
111 
112 std::ostream& operator<<(std::ostream& os,
114  switch (e) {
116  os << "sendHeaders";
117  break;
119  os << "sendBody";
120  break;
122  os << "sendChunkHeader";
123  break;
125  os << "sendChunkTerminator";
126  break;
128  os << "sendTrailers";
129  break;
131  os << "sendEOM";
132  break;
134  os << "eomFlushed";
135  break;
136  }
137 
138  return os;
139 }
140 
141 }
std::ostream & operator<<(std::ostream &os, const HeaderTable &table)
static std::pair< State, bool > find(State s, Event e)
static set< string > s