4 // A Client represents a single connection from a client (watching a single stream).
15 // Digested statistics for writing to logs etc.
16 // Note that "referer" and "user_agent" here are already escaped for scary characters.
20 std::string remote_addr;
22 std::string user_agent;
23 timespec connect_time;
26 size_t num_loss_events;
32 // Serialization/deserialization.
33 Client(const ClientProto &serialized, Stream *stream);
34 ClientProto serialize() const;
36 ClientStats get_stats() const;
38 // The file descriptor associated with this socket.
41 // When the client connected, in terms of CLOCK_MONOTONIC_COARSE.
42 timespec connect_time;
44 // Some information only used for logging.
45 std::string remote_addr;
47 std::string user_agent;
49 enum State { READING_REQUEST, SENDING_HEADER, SENDING_DATA, SENDING_SHORT_RESPONSE, WAITING_FOR_KEYFRAME, PREBUFFERING };
50 State state = READING_REQUEST;
52 // The HTTP request, as sent by the client. If we are in READING_REQUEST,
53 // this might not be finished.
56 // What stream we're connecting to; parsed from <request>.
57 // Not relevant for READING_REQUEST.
59 Stream *stream = nullptr;
61 // Whether we should close the connection after sending the response.
62 // Not relevant for READING_REQUEST. Must be true if http_11 is false.
63 bool close_after_response;
65 // Whether the request came in over HTTP/1.1 or higher.
68 // The header we want to send, or the response with headers if we know
69 // it in its entirety after reading the request (typically an error).
70 // This is nominally a copy of Stream::header, but since that might
71 // change on reconnects etc., we keep a local copy here. Only relevant
72 // for SENDING_HEADER or SENDING_SHORT_RESPONSE; blank otherwise.
74 // Must start with the string "HTTP/1.0 ", which will be changed to 1.1
76 std::string header_or_short_response;
78 // Number of bytes we've sent of the header. Only relevant for SENDING_HEADER
79 // or SENDING_SHORT_RESPONSE.
80 size_t header_or_short_response_bytes_sent = 0;
82 // Number of bytes we are into the stream (ie., the end of last send).
83 // -1 means we want to send from the end of the backlog (the normal case),
84 // although only at a keyframe.
85 // -2 means we want to send from the _beginning_ of the backlog.
86 // Once we go into WAITING_FOR_KEYFRAME, PREBUFFERING or SENDING_DATA,
87 // these negative values will be translated to real numbers.
88 size_t stream_pos = 0;
90 // Number of bytes we've sent of data. Only relevant for SENDING_DATA.
91 size_t bytes_sent = 0;
93 // Number of times we've skipped forward due to the backlog being too big,
94 // and how many bytes we've skipped over in all. Only relevant for SENDING_DATA.
95 size_t bytes_lost = 0, num_loss_events = 0;
97 TLSContext *tls_context = nullptr;
98 const unsigned char *tls_data_to_send = nullptr;
99 unsigned tls_data_left_to_send = 0;
100 bool in_ktls_mode = false;
103 #endif // !defined(_CLIENT_H)