#include <Stream.h>

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

Classes

class  DeferredParams
 

Public Member Functions

 Stream (const Comm::ConnectionPointer &aConn, ClientHttpRequest *aReq)
 construct with HTTP/1.x details More...
 
 ~Stream () override
 
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 Error &, const LogTagsErrors &)
 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...
 
ClientHttpRequesthttp
 
HttpReplyreply
 
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...
 
flags
 
DeferredParams deferredparams
 
int64_t writtenToSocket
 

Private Member Functions

 MEMPROXY_CLASS (Stream)
 
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.

HTTP/1.x:

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 72 of file Stream.h.

Constructor & Destructor Documentation

◆ Stream()

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

◆ ~Stream()

Http::Stream::~Stream ( )
override

Definition at line 39 of file Stream.cc.

References assert, and httpRequestFree().

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
false

first update iterator "i" if needed

Definition at line 188 of file Stream.cc.

References assert, and debugs.

◆ connRegistered()

bool Http::Stream::connRegistered ( ) const
inline

Definition at line 85 of file Stream.h.

References connRegistered_.

◆ deferRecipientForLater()

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

Definition at line 555 of file Stream.cc.

References assert, and debugs.

◆ doClose()

void Http::Stream::doClose ( )
private

Definition at line 655 of file Stream.cc.

◆ finished()

void Http::Stream::finished ( )

Definition at line 533 of file Stream.cc.

References assert, clientStreamDetach(), conn, and CodeContext::Reset().

◆ getClientReplyContext()

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

◆ getConn()

ConnStateData * Http::Stream::getConn ( ) const

Definition at line 516 of file Stream.cc.

References assert.

◆ getNextRangeOffset()

int64_t Http::Stream::getNextRangeOffset ( ) const

Definition at line 131 of file Stream.cc.

References assert, debugs, and HttpHdrRangeSpec::UnknownPosition.

◆ getTail()

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

Definition at line 501 of file Stream.cc.

◆ initiateClose()

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

called when we encounter a response-related error

Definition at line 548 of file Stream.cc.

References debugs.

◆ lengthToSend()

size_t Http::Stream::lengthToSend ( Range< int64_t > const &  available) const

Definition at line 337 of file Stream.cc.

References assert, min(), Range< C, S >::size(), and Range< C, S >::start.

◆ mayUseConnection() [1/2]

bool Http::Stream::mayUseConnection ( ) const
inline

Definition at line 143 of file Stream.h.

References mayUseConnection_.

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

◆ mayUseConnection() [2/2]

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

Definition at line 145 of file Stream.h.

References debugs, and mayUseConnection_.

◆ MEMPROXY_CLASS()

Http::Stream::MEMPROXY_CLASS ( Stream  )
private

◆ multipartRangeRequest()

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

Definition at line 125 of file Stream.cc.

◆ noteIoError()

void Http::Stream::noteIoError ( const Error error,
const LogTagsErrors lte 
)

remembers the abnormal connection termination for logging purposes

Definition at line 524 of file Stream.cc.

References error().

◆ 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 360 of file Stream.cc.

References assert, and debugs.

◆ packChunk()

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

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

Definition at line 578 of file Stream.cc.

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

◆ packRange()

void Http::Stream::packRange ( StoreIOBuffer const &  source,
MemBuf mb 
)
private

◆ prepareReply()

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

Definition at line 566 of file Stream.cc.

◆ pullData()

void Http::Stream::pullData ( )

◆ registerWithConn()

void Http::Stream::registerWithConn ( )

Definition at line 52 of file Stream.cc.

References assert.

Referenced by ConnStateData::buildFakeRequest().

◆ sendBody()

void Http::Stream::sendBody ( StoreIOBuffer  bodyData)

◆ sendStartOfMessage()

◆ socketState()

◆ startOfOutput()

bool Http::Stream::startOfOutput ( ) const

Definition at line 61 of file Stream.cc.

◆ writeComplete()

void Http::Stream::writeComplete ( size_t  size)

Member Data Documentation

◆ clientConnection

Comm::ConnectionPointer Http::Stream::clientConnection

Definition at line 134 of file Stream.h.

◆ connRegistered_

bool Http::Stream::connRegistered_
private

Definition at line 169 of file Stream.h.

Referenced by connRegistered().

◆ deferred

unsigned Http::Stream::deferred

Definition at line 139 of file Stream.h.

◆ deferredparams

DeferredParams Http::Stream::deferredparams

Definition at line 159 of file Stream.h.

Referenced by Stream().

◆ 

◆ http

ClientHttpRequest* Http::Stream::http

Definition at line 135 of file Stream.h.

Referenced by Stream(), clientProcessRequest(), and ConnStateData::serveDelayedError().

◆ mayUseConnection_

bool Http::Stream::mayUseConnection_
private

Definition at line 168 of file Stream.h.

Referenced by mayUseConnection().

◆ parsed_ok

unsigned Http::Stream::parsed_ok

◆ reply

HttpReply* Http::Stream::reply

Definition at line 136 of file Stream.h.

◆ reqbuf

◆ writeQuotaHandler

MessageBucket::Pointer Http::Stream::writeQuotaHandler
private

Definition at line 171 of file Stream.h.

◆ writtenToSocket

int64_t Http::Stream::writtenToSocket

Definition at line 160 of file Stream.h.


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors