http.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 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_HTTP_H
10 #define SQUID_HTTP_H
11 
12 #include "clients/Client.h"
13 #include "comm.h"
14 #include "http/forward.h"
15 #include "http/StateFlags.h"
16 #include "sbuf/SBuf.h"
17 
18 class FwdState;
19 class HttpHeader;
20 class String;
21 
22 class HttpStateData : public Client
23 {
25 
26 public:
27 
30  {
31  public:
33 
36  Answers make(const Answers ans, const char *why);
37 
39  const char *reason;
40  const StoreEntry *entry;
42  };
43 
46 
48  StoreEntry * entry,
49  const AccessLogEntryPointer &al,
50  HttpHeader * hdr_out,
51  const Http::StateFlags &flags);
52 
53  virtual const Comm::ConnectionPointer & dataConnection() const;
54  /* should be private */
55  bool sendRequest();
56  void processReplyHeader();
57  void processReplyBody();
58  void readReply(const CommIoCbParams &io);
59  virtual void maybeReadVirginBody(); // read response data from the network
60 
61  // Checks whether the response is cacheable/shareable.
63 
64  CachePeer *_peer = nullptr; /* CachePeer request made to */
65  int eof = 0; /* reached end-of-object? */
66  int lastChunk = 0; /* reached last chunk of a chunk-encoded reply */
69  bool ignoreCacheControl = false;
70  bool surrogateNoStore = false;
71 
74 
76 
77 protected:
78  /* Client API */
79  virtual void noteDelayAwareReadChance();
80 
81  void processReply();
82  void proceedAfter1xx();
83  void handle1xx(HttpReply *msg);
84  void drop1xx(const char *reason);
85 
86 private:
98  };
102  void checkDateSkew(HttpReply *);
103 
105  void truncateVirginBody();
106 
107  virtual void start();
108  virtual void haveParsedReplyHeaders();
109  virtual bool getMoreRequestBody(MemBuf &buf);
110  virtual void closeServer(); // end communication with the server
111  virtual bool doneWithServer() const; // did we end communication?
112  virtual void abortAll(const char *reason); // abnormal termination
113  virtual bool mayReadVirginReplyBody() const;
114 
115  void abortTransaction(const char *reason) { abortAll(reason); } // abnormal termination
116 
126  bool maybeMakeSpaceAvailable(bool grow);
127 
128  // consuming request body
129  virtual void handleMoreRequestBodyAvailable();
130  virtual void handleRequestBodyProducerAborted();
131 
132  void writeReplyBody();
134  bool finishingBrokenPost();
136  void doneSendingRequestBody();
138  virtual void sentRequestBody(const CommIoCbParams &io);
139  void wroteLast(const CommIoCbParams &io);
140  void sendComplete();
141  void httpStateConnClosed(const CommCloseCbParams &params);
142  void httpTimeout(const CommTimeoutCbParams &params);
143 
145  void forwardUpgrade(HttpHeader&);
146  static bool decideIfWeDoRanges (HttpRequest * orig_request);
147  bool peerSupportsConnectionPinning() const;
148  const char *blockSwitchingProtocols(const HttpReply&) const;
149 
153 
155  int64_t payloadSeen = 0;
157  int64_t payloadTruncated = 0;
158 
161  bool sawDateGoBack = false;
162 };
163 
164 std::ostream &operator <<(std::ostream &os, const HttpStateData::ReuseDecision &d);
165 
167 void httpStart(FwdState *);
169 
170 #endif /* SQUID_HTTP_H */
171 
void drop1xx(const char *reason)
Definition: http.cc:805
virtual void haveParsedReplyHeaders()
called when we have final (possibly adapted) reply headers; kids extend
Definition: http.cc:937
bool maybeMakeSpaceAvailable(bool grow)
Definition: http.cc:1599
void truncateVirginBody()
Definition: http.cc:1372
StoreEntry * entry
Definition: Client.h:176
bool ignoreCacheControl
Definition: http.h:69
Definition: Client.h:35
virtual bool getMoreRequestBody(MemBuf &buf)
either fill buf with available [encoded] request body bytes or return false
Definition: http.cc:2415
Http::StateFlags flags
Definition: http.h:67
Answers make(const Answers ans, const char *why)
stores the corresponding decision
Definition: http.cc:2616
String * upgradeHeaderOut
Upgrade header value sent to the origin server or cache peer.
Definition: http.h:73
void checkDateSkew(HttpReply *)
Definition: http.cc:624
int64_t payloadTruncated
positive when we read more than we wanted
Definition: http.h:157
virtual void abortAll(const char *reason)
abnormal transaction termination; reason is for debugging only
Definition: http.cc:2605
const Http::StatusCode statusCode
HTTP status for debugging.
Definition: http.h:41
virtual bool mayReadVirginReplyBody() const
whether we may receive more virgin response body bytes
Definition: http.cc:1564
bool surrogateNoStore
Definition: http.h:70
int lastChunk
Definition: http.h:66
bool finishingBrokenPost()
if broken posts are enabled for the request, try to fix and return true
Definition: http.cc:2476
CachePeer * _peer
Definition: http.h:64
#define CBDATA_CLASS(type)
Definition: cbdata.h:302
Definition: SBuf.h:94
mb_size_t buildRequestPrefix(MemBuf *mb)
Definition: http.cc:2284
ConnectionStatus statusIfComplete() const
Definition: http.cc:1067
AsyncCall::Pointer closeHandler
Definition: http.h:93
ConnectionStatus
Definition: http.h:94
HttpStateData(FwdState *)
Definition: http.cc:77
const char * blockSwitchingProtocols(const HttpReply &) const
Definition: http.cc:823
bool sendRequest()
Definition: http.cc:2328
void processReplyBody()
Definition: http.cc:1455
Comm::ConnectionPointer serverConnection
Definition: http.h:92
StatusCode
Definition: StatusCode.h:20
void keepaliveAccounting(HttpReply *)
Definition: http.cc:604
bool decodeAndWriteReplyBody()
Definition: http.cc:1423
void readReply(const CommIoCbParams &io)
Definition: http.cc:1175
static bool decideIfWeDoRanges(HttpRequest *orig_request)
Definition: http.cc:2254
@ COMPLETE_NONPERSISTENT_MSG
Definition: http.h:97
void sendComplete()
successfully wrote the entire request (including body, last-chunk, etc.)
Definition: http.cc:1673
void httpStart(FwdState *)
Definition: http.cc:2449
void processReplyHeader()
Definition: http.cc:641
ReuseDecision(const StoreEntry *e, const Http::StatusCode code)
Definition: http.cc:2612
@ COMPLETE_PERSISTENT_MSG
Definition: http.h:96
SBuf inBuf
I/O buffer for receiving server responses.
Definition: http.h:68
virtual void handleMoreRequestBodyAvailable()
Definition: http.cc:2544
void handle1xx(HttpReply *msg)
ignore or start forwarding the 1xx response (a.k.a., control message)
Definition: http.cc:746
SBuf httpMakeVaryMark(HttpRequest *request, HttpReply const *reply)
Definition: http.cc:585
Definition: MemBuf.h:24
const StoreEntry * entry
entry for debugging
Definition: http.h:40
void doneSendingRequestBody()
Definition: http.cc:2528
unsigned char code
Definition: html_quote.c:20
virtual void handleRequestBodyProducerAborted()
Definition: http.cc:2576
void proceedAfter1xx()
restores state and resumes processing after 1xx is ignored or forwarded
Definition: http.cc:850
ConnectionStatus persistentConnStatus() const
Definition: http.cc:1118
@ INCOMPLETE_MSG
Definition: http.h:95
void httpTimeout(const CommTimeoutCbParams &params)
Definition: http.cc:144
Answers answer
the decision id
Definition: http.h:38
virtual bool doneWithServer() const
Definition: http.cc:1705
void abortTransaction(const char *reason)
Definition: http.h:115
void writeReplyBody()
Definition: http.cc:1400
void httpStateConnClosed(const CommCloseCbParams &params)
Definition: http.cc:136
virtual const Comm::ConnectionPointer & dataConnection() const
Definition: http.cc:130
std::ostream & operator<<(std::ostream &os, const HttpStateData::ReuseDecision &d)
Definition: http.cc:2623
ReuseDecision::Answers reusableReply(ReuseDecision &decision)
Definition: http.cc:294
Http1::TeChunkedParser * httpChunkDecoder
Definition: http.h:152
void wroteLast(const CommIoCbParams &io)
called after writing the very last request byte (body, last-chunk, etc)
Definition: http.cc:1636
Http1::ResponseParserPointer hp
Parser being used at present to parse the HTTP/ICY server response.
Definition: http.h:151
assists in making and relaying entry caching/sharing decision
Definition: http.h:30
virtual void noteDelayAwareReadChance()
Definition: http.cc:1168
const char * reason
the decision reason
Definition: http.h:39
int httpCachable(const HttpRequestMethod &)
int eof
Definition: http.h:65
bool sawDateGoBack
Definition: http.h:161
bool peerSupportsConnectionPinning() const
Definition: http.cc:879
virtual void maybeReadVirginBody()
read response data from the network
Definition: http.cc:1573
void processReply()
Definition: http.cc:1271
bool finishingChunkedRequest()
if needed, write last-chunk to end the request body and return true
Definition: http.cc:2511
virtual void start()
called by AsyncStart; do not call directly
Definition: http.cc:2456
ssize_t mb_size_t
Definition: MemBuf.h:17
static void httpBuildRequestHeader(HttpRequest *request, StoreEntry *entry, const AccessLogEntryPointer &al, HttpHeader *hdr_out, const Http::StateFlags &flags)
Definition: http.cc:1825
virtual void sentRequestBody(const CommIoCbParams &io)
Definition: http.cc:2596
void processSurrogateControl(HttpReply *)
Definition: http.cc:256
int64_t payloadSeen
amount of message payload/body received so far.
Definition: http.h:155
bool continueAfterParsingHeader()
Definition: http.cc:1302
virtual void closeServer()
Definition: http.cc:1692
void requestBodyHandler(MemBuf &)
void forwardUpgrade(HttpHeader &)
Definition: http.cc:2002
HttpRequestPointer request
Definition: Client.h:178
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
~HttpStateData()
Definition: http.cc:113

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors