Stream.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_SRC_HTTP_STREAM_H
10 #define SQUID_SRC_HTTP_STREAM_H
11 
12 #include "clientStreamForward.h"
13 #include "comm/forward.h"
14 #include "debug/Stream.h"
15 #include "error/Error.h"
16 #include "http/forward.h"
17 #include "log/forward.h"
18 #include "mem/forward.h"
19 #include "servers/forward.h"
20 #include "StoreIOBuffer.h"
21 #if USE_DELAY_POOLS
22 #include "MessageBucket.h"
23 #endif
24 
25 namespace Http
26 {
27 
72 class Stream : public RefCountable
73 {
75 
76 public:
79  ~Stream() override;
80 
82  void registerWithConn();
83 
85  bool connRegistered() const {return connRegistered_;};
86 
88  bool startOfOutput() const;
89 
91  void writeComplete(size_t size);
92 
94  void pullData();
95 
97  bool multipartRangeRequest() const;
98 
99  int64_t getNextRangeOffset() const;
100  bool canPackMoreRanges() const;
101  size_t lengthToSend(Range<int64_t> const &available) const;
102 
104 
106  void sendStartOfMessage(HttpReply *, StoreIOBuffer bodyData);
108  void sendBody(StoreIOBuffer bodyData);
111  void noteSentBodyBytes(size_t);
112 
114  void buildRangeHeader(HttpReply *);
115 
116  clientStreamNode * getTail() const;
118 
119  ConnStateData *getConn() const;
120 
122  void noteIoError(const Error &, const LogTagsErrors &);
123 
125  void finished();
126 
128  void initiateClose(const char *reason);
129 
131 
132 public: // HTTP/1.x state data
133 
135  ClientHttpRequest *http; /* we pretend to own that Job */
138  struct {
139  unsigned deferred:1;
140  unsigned parsed_ok:1;
141  } flags;
142 
143  bool mayUseConnection() const {return mayUseConnection_;}
144 
145  void mayUseConnection(bool aBool) {
146  mayUseConnection_ = aBool;
147  debugs(33, 3, "This " << this << " marked " << aBool);
148  }
149 
151  {
152 
153  public:
157  };
158 
161 
162 private:
163  void prepareReply(HttpReply *);
164  void packChunk(const StoreIOBuffer &bodyData, MemBuf &);
165  void packRange(StoreIOBuffer const &, MemBuf *);
166  void doClose();
167 
168  bool mayUseConnection_; /* This request may use the connection. Don't read anymore requests for now */
170 #if USE_DELAY_POOLS
172 #endif
173 };
174 
175 } // namespace Http
176 
177 #endif /* SQUID_SRC_HTTP_STREAM_H */
178 
ConnStateData * getConn() const
Definition: Stream.cc:517
void sendStartOfMessage(HttpReply *, StoreIOBuffer bodyData)
send an HTTP reply message headers and maybe some initial payload
Definition: Stream.cc:267
StoreIOBuffer queuedBuffer
Definition: Stream.h:156
void registerWithConn()
register this stream with the Server
Definition: Stream.cc:53
void buildRangeHeader(HttpReply *)
add Range headers (if any) to the given HTTP reply message
Definition: Stream.cc:417
bool connRegistered() const
whether it is registered with a Server
Definition: Stream.h:85
void finished()
cleanup when the transaction has finished. may destroy 'this'
Definition: Stream.cc:534
void mayUseConnection(bool aBool)
Definition: Stream.h:145
char reqbuf[HTTP_REQBUF_SZ]
Definition: Stream.h:137
MessageBucket::Pointer writeQuotaHandler
response write limiter, if configured
Definition: Stream.h:171
clientStream_status_t socketState()
Adapt stream status to account for Range cases.
Definition: Stream.cc:211
~Stream() override
Definition: Stream.cc:40
int64_t writtenToSocket
Definition: Stream.h:160
int64_t getNextRangeOffset() const
Definition: Stream.cc:132
Definition: forward.h:17
bool multipartRangeRequest() const
Definition: Stream.cc:126
void writeComplete(size_t size)
update stream state after a write, may initiate more I/O
Definition: Stream.cc:68
a transaction problem
Definition: Error.h:27
void noteIoError(const Error &, const LogTagsErrors &)
update state to reflect I/O error
Definition: Stream.cc:525
Definition: Range.h:18
bool mayUseConnection() const
Definition: Stream.h:143
size_t lengthToSend(Range< int64_t > const &available) const
Definition: Stream.cc:338
bool canPackMoreRanges() const
Definition: Stream.cc:189
int size
Definition: ModDevPoll.cc:69
void prepareReply(HttpReply *)
Definition: Stream.cc:567
Definition: MemBuf.h:23
clientStreamNode * getClientReplyContext() const
Definition: Stream.cc:511
Comm::ConnectionPointer clientConnection
details about the client connection socket
Definition: Stream.h:134
Stream(const Comm::ConnectionPointer &aConn, ClientHttpRequest *aReq)
construct with HTTP/1.x details
Definition: Stream.cc:24
void packChunk(const StoreIOBuffer &bodyData, MemBuf &)
Definition: Stream.cc:579
ClientHttpRequest * http
Definition: Stream.h:135
bool mayUseConnection_
Definition: Stream.h:168
clientStreamNode * node
Definition: Stream.h:154
HttpReply * reply
Definition: Stream.h:136
bool connRegistered_
Definition: Stream.h:169
clientStreamNode * getTail() const
Definition: Stream.cc:502
unsigned deferred
This is a pipelined request waiting for the current object to complete.
Definition: Stream.h:139
void doClose()
Definition: Stream.cc:656
unsigned parsed_ok
Was this parsed correctly?
Definition: Stream.h:140
clientStream_status_t
Definition: enums.h:120
bool startOfOutput() const
whether the reply has started being sent
Definition: Stream.cc:62
void pullData()
get more data to send
Definition: Stream.cc:110
MEMPROXY_CLASS(Stream)
struct Http::Stream::@65 flags
void deferRecipientForLater(clientStreamNode *, HttpReply *, StoreIOBuffer receivedData)
Definition: Stream.cc:556
#define HTTP_REQBUF_SZ
Definition: forward.h:14
void packRange(StoreIOBuffer const &, MemBuf *)
Definition: Stream.cc:595
void sendBody(StoreIOBuffer bodyData)
send some HTTP reply message payload
Definition: Stream.cc:315
DeferredParams deferredparams
Definition: Stream.h:159
void noteSentBodyBytes(size_t)
Definition: Stream.cc:361
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
void initiateClose(const char *reason)
terminate due to a send/write error (may continue reading)
Definition: Stream.cc:549

 

Introduction

Documentation

Support

Miscellaneous