#include <Stream.h>

Inheritance diagram for Http::Stream:
Collaboration diagram for Http::Stream:


class  DeferredParams

Public Member Functions

 Stream (const Comm::ConnectionPointer &aConn, ClientHttpRequest *aReq)
 construct with HTTP/1.x details More...
 ~Stream ()
void registerWithConn ()
 register this stream with the Server More...
bool connRegistered () const
 whether it is registered with a Server More...
bool startOfOutput () const
 whether the reply has started being sent More...
void writeComplete (size_t size)
 update stream state after a write, may initiate more I/O More...
void pullData ()
 get more data to send More...
bool multipartRangeRequest () const
int64_t getNextRangeOffset () const
bool canPackMoreRanges () const
size_t lengthToSend (Range< int64_t > const &available) const
clientStream_status_t socketState ()
 Adapt stream status to account for Range cases. More...
void sendStartOfMessage (HttpReply *, StoreIOBuffer bodyData)
 send an HTTP reply message headers and maybe some initial payload More...
void sendBody (StoreIOBuffer bodyData)
 send some HTTP reply message payload More...
void noteSentBodyBytes (size_t)
void buildRangeHeader (HttpReply *)
 add Range headers (if any) to the given HTTP reply message More...
clientStreamNodegetTail () const
clientStreamNodegetClientReplyContext () const
ConnStateDatagetConn () const
void noteIoError (const int xerrno)
 update state to reflect I/O error More...
void finished ()
 cleanup when the transaction has finished. may destroy 'this' More...
void initiateClose (const char *reason)
 terminate due to a send/write error (may continue reading) More...
void deferRecipientForLater (clientStreamNode *, HttpReply *, StoreIOBuffer receivedData)
bool mayUseConnection () const
void mayUseConnection (bool aBool)

Public Attributes

Comm::ConnectionPointer clientConnection
 details about the client connection socket More...
char reqbuf [HTTP_REQBUF_SZ]
struct {
   unsigned   deferred:1
 This is a pipelined request waiting for the current object to complete. More...
   unsigned   parsed_ok:1
 Was this parsed correctly? More...
DeferredParams deferredparams
int64_t writtenToSocket

Private Member Functions

void prepareReply (HttpReply *)
void packChunk (const StoreIOBuffer &bodyData, MemBuf &)
void packRange (StoreIOBuffer const &, MemBuf *)
void doClose ()

Private Attributes

bool mayUseConnection_
bool connRegistered_
MessageBucket::Pointer writeQuotaHandler
 response write limiter, if configured More...

Detailed Description

The processing context for a single HTTP transaction (stream).

A stream lifetime extends from directly after a request has been parsed off the client connection buffer, until the last byte of both request and reply payload (if any) have been written, or it is otherwise explicitly terminated.

Streams self-register with the Http::Server Pipeline being managed by the Server for the connection on which the request was received.

The socket level management and I/O is done by a Server which owns us. The scope of this objects control over a socket consists of the data buffer received from the Server with an initially unknown length. When that length is known it sets the end boundary of our access to the buffer.

The individual processing actions are done by other Jobs which we start.

When a stream is completed the finished() method needs to be called which will perform all cleanup and deregistration operations. If the reason for finishing is an error, then notifyIoError() needs to be called prior to the finished() method. The caller should follow finished() with a call to ConnStateData::kick() to resume processing of other transactions or I/O on the connection.

Alternatively the initiateClose() method can be called to terminate the whole client connection and all other pending streams.


When HTTP/1 pipeline is operating there may be multiple transactions using the client connection. Only the back() stream may read from the connection, and only the front() stream may write to it. A stream which needs to read or write to the connection but does not meet those criteria must be shifted to the deferred state.

XXX: If an async call ends the ClientHttpRequest job, Http::Stream (and ConnStateData) may not know about it, leading to segfaults and assertions. This is difficult to fix because ClientHttpRequest lacks a good way to communicate its ongoing destruction back to the Http::Stream which pretends to "own" *http.

Definition at line 69 of file Stream.h.

Constructor & Destructor Documentation

◆ Stream()

Http::Stream::Stream ( const Comm::ConnectionPointer aConn,
ClientHttpRequest aReq 

◆ ~Stream()

Http::Stream::~Stream ( )

Definition at line 39 of file Stream.cc.

References assert, getTail(), http, and httpRequestFree().

Referenced by Http::StatusCodeString().

Member Function Documentation

◆ buildRangeHeader()

◆ canPackMoreRanges()

bool Http::Stream::canPackMoreRanges ( ) const

increments iterator "i" used by clientPackMoreRanges

Return values
truethere is still data available to pack more ranges

first update iterator "i" if needed

Definition at line 191 of file Stream.cc.

References assert, clientConnection, HttpHdrRangeIter::currentSpec(), HttpHdrRangeIter::debt(), debugs, HttpHdrRangeIter::end, http, HttpHdrRangeIter::pos, ClientHttpRequest::range_iter, true, and HttpHdrRangeIter::updateSpec().

Referenced by connRegistered(), getNextRangeOffset(), lengthToSend(), packRange(), socketState(), and Http::StatusCodeString().

◆ connRegistered()

◆ deferRecipientForLater()

void Http::Stream::deferRecipientForLater ( clientStreamNode node,
HttpReply rep,
StoreIOBuffer  receivedData 

◆ doClose()

void Http::Stream::doClose ( )

Definition at line 693 of file Stream.cc.

References clientConnection, and Comm::Connection::close().

◆ finished()

void Http::Stream::finished ( )

◆ getClientReplyContext()

◆ getConn()

◆ getNextRangeOffset()

◆ getTail()

clientStreamNode * Http::Stream::getTail ( ) const

◆ initiateClose()

void Http::Stream::initiateClose ( const char *  reason)

called when we encounter a response-related error

Definition at line 585 of file Stream.cc.

References clientConnection, debugs, getConn(), and ConnStateData::stopSending().

Referenced by connRegistered(), Http::StatusCodeString(), and writeComplete().

◆ lengthToSend()

◆ mayUseConnection() [1/2]

bool Http::Stream::mayUseConnection ( ) const

Definition at line 140 of file Stream.h.

References mayUseConnection_.

Referenced by ConnStateData::buildFakeRequest(), and clientProcessRequest().

◆ mayUseConnection() [2/2]

void Http::Stream::mayUseConnection ( bool  aBool)

Definition at line 142 of file Stream.h.

References debugs, and mayUseConnection_.


Http::Stream::MEMPROXY_CLASS ( Stream  )

◆ multipartRangeRequest()

bool Http::Stream::multipartRangeRequest ( ) const
true if the HTTP request is for multiple ranges

Definition at line 129 of file Stream.cc.

References http, and ClientHttpRequest::multipartRangeRequest().

Referenced by connRegistered(), sendBody(), sendStartOfMessage(), and Http::StatusCodeString().

◆ noteIoError()

void Http::Stream::noteIoError ( const int  xerrno)

remembers the abnormal connection termination for logging purposes

Definition at line 561 of file Stream.cc.

References LogTags::Errors::aborted, LogTags::err, http, ClientHttpRequest::logType, and LogTags::Errors::timedout.

Referenced by connRegistered(), and Http::StatusCodeString().

◆ noteSentBodyBytes()

void Http::Stream::noteSentBodyBytes ( size_t  bytes)

update stream state when N bytes are being sent. NP: Http1Server bytes actually not sent yet, just packed into a MemBuf ready

Definition at line 362 of file Stream.cc.

References assert, HttpHdrRangeIter::debt(), debugs, http, ClientHttpRequest::Out::offset, ClientHttpRequest::out, HttpRequest::range, ClientHttpRequest::range_iter, and ClientHttpRequest::request.

Referenced by connRegistered(), packChunk(), packRange(), sendBody(), sendStartOfMessage(), and Http::StatusCodeString().

◆ packChunk()

void Http::Stream::packChunk ( const StoreIOBuffer bodyData,
MemBuf mb 

Packs bodyData into mb using chunked encoding. Packs the last-chunk if bodyData is empty.

Definition at line 615 of file Stream.cc.

References MemBuf::append(), Packable::appendf(), StoreIOBuffer::data, lengthToSend(), noteSentBodyBytes(), PRIX64, and StoreIOBuffer::range().

Referenced by sendBody(), and sendStartOfMessage().

◆ packRange()

◆ prepareReply()

void Http::Stream::prepareReply ( HttpReply rep)

Definition at line 603 of file Stream.cc.

References buildRangeHeader(), http, HttpRequest::range, reply, and ClientHttpRequest::request.

Referenced by sendStartOfMessage().

◆ pullData()

◆ registerWithConn()

void Http::Stream::registerWithConn ( )

◆ sendBody()

◆ sendStartOfMessage()

◆ socketState()

◆ startOfOutput()

bool Http::Stream::startOfOutput ( ) const

Definition at line 61 of file Stream.cc.

References http, ClientHttpRequest::out, and ClientHttpRequest::Out::size.

Referenced by connRegistered(), and Http::StatusCodeString().

◆ writeComplete()

Member Data Documentation

◆ clientConnection

Comm::ConnectionPointer Http::Stream::clientConnection

◆ connRegistered_

bool Http::Stream::connRegistered_

Definition at line 166 of file Stream.h.

Referenced by connRegistered(), finished(), and registerWithConn().

◆ deferred

unsigned Http::Stream::deferred

Definition at line 136 of file Stream.h.

◆ deferredparams

DeferredParams Http::Stream::deferredparams

Definition at line 156 of file Stream.h.

Referenced by deferRecipientForLater(), and Stream().

◆ flags

◆ http

◆ mayUseConnection_

bool Http::Stream::mayUseConnection_

Definition at line 165 of file Stream.h.

Referenced by mayUseConnection().

◆ parsed_ok

unsigned Http::Stream::parsed_ok

◆ reply

HttpReply* Http::Stream::reply

Definition at line 133 of file Stream.h.

Referenced by getNextRangeOffset(), prepareReply(), pullData(), and socketState().

◆ reqbuf

char Http::Stream::reqbuf[HTTP_REQBUF_SZ]

◆ writeQuotaHandler

MessageBucket::Pointer Http::Stream::writeQuotaHandler

Definition at line 168 of file Stream.h.

Referenced by sendStartOfMessage().

◆ writtenToSocket

int64_t Http::Stream::writtenToSocket

Definition at line 157 of file Stream.h.

The documentation for this class was generated from the following files:






Web Site Translations