HttpTunneler.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 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_CLIENTS_HTTP_TUNNELER_H
10 #define SQUID_SRC_CLIENTS_HTTP_TUNNELER_H
11 
12 #include "base/AsyncCbdataCalls.h"
13 #include "base/AsyncJob.h"
14 #include "clients/forward.h"
16 #include "CommCalls.h"
17 #if USE_DELAY_POOLS
18 #include "DelayId.h"
19 #endif
20 #include "http/forward.h"
21 
22 class ErrorState;
25 
26 namespace Http
27 {
28 
32 class Tunneler: virtual public AsyncJob
33 {
35 
36 public:
38  template <class Initiator>
40  {
41  public:
42  // initiator method to receive our answer
43  typedef void (Initiator::*Method)(Http::TunnelerAnswer &);
44 
45  CbDialer(Method method, Initiator *initiator): initiator_(initiator), method_(method) {}
46  virtual ~CbDialer() = default;
47 
48  /* CallDialer API */
49  bool canDial(AsyncCall &) { return initiator_.valid(); }
50  void dial(AsyncCall &) {((*initiator_).*method_)(*this); }
51  virtual void print(std::ostream &os) const override {
52  os << '(' << static_cast<const Http::TunnelerAnswer&>(*this) << ')';
53  }
54  private:
57  };
58 
59 public:
60  Tunneler(const Comm::ConnectionPointer &conn, const HttpRequestPointer &req, AsyncCall::Pointer &aCallback, time_t timeout, const AccessLogEntryPointer &alp);
61  Tunneler(const Tunneler &) = delete;
62  Tunneler &operator =(const Tunneler &) = delete;
63 
64 #if USE_DELAY_POOLS
65  void setDelayId(DelayId delay_id) {delayId = delay_id;}
66 #endif
67 
70 
71 protected:
72  /* AsyncJob API */
73  virtual ~Tunneler();
74  virtual void start();
75  virtual bool doneAll() const;
76  virtual void swanSong();
77  virtual const char *status() const;
78 
80  void watchForClosures();
81  void handleTimeout(const CommTimeoutCbParams &);
82  void startReadingResponse();
83  void writeRequest();
85  void handleReadyRead(const CommIoCbParams&);
86  void readMore();
87  void handleResponse(const bool eof);
88  void bailOnResponseError(const char *error, HttpReply *);
89 
91  void bailWith(ErrorState*);
92 
94  void sendSuccess();
95 
97  void callBack();
98 
100  void disconnect();
101 
103 
104 private:
108 
113  time_t lifetimeLimit;
115 #if USE_DELAY_POOLS
117 #endif
118 
122 
123  const time_t startTime;
124 
127 };
128 
129 } // namespace Http
130 
131 #endif /* SQUID_SRC_CLIENTS_HTTP_TUNNELER_H */
132 
void startReadingResponse()
AsyncCall::Pointer reader
called when the response should be read
Definition: HttpTunneler.h:106
void sendSuccess()
sends the ready-to-use tunnel to the initiator
Comm::ConnectionPointer connection
TCP connection to the cache_peer.
Definition: HttpTunneler.h:109
time_t lifetimeLimit
do not run longer than this
Definition: HttpTunneler.h:113
virtual void print(std::ostream &os) const override
Definition: HttpTunneler.h:51
void disconnect()
a bailWith(), sendSuccess() helper: stops monitoring the connection
void bailWith(ErrorState *)
sends the given error to the initiator
virtual bool doneAll() const
whether positive goal has been reached
Definition: HttpTunneler.cc:56
void handleTimeout(const CommTimeoutCbParams &)
The connection read timeout callback handler.
void error(char *format,...)
Definition: SBuf.h:86
void dial(AsyncCall &)
Definition: HttpTunneler.h:50
Definition: forward.h:21
bool requestWritten
whether we successfully wrote the request
Definition: HttpTunneler.h:125
Callback dialer API to allow Tunneler to set the answer.
Definition: HttpTunneler.h:39
void bailOnResponseError(const char *error, HttpReply *)
Method method_
initiator_ method to call with the answer
Definition: HttpTunneler.h:56
const time_t startTime
when the tunnel establishment started
Definition: HttpTunneler.h:123
virtual ~CbDialer()=default
virtual void start()
called by AsyncStart; do not call directly
Definition: HttpTunneler.cc:72
void handleReadyRead(const CommIoCbParams &)
Called when we read [a part of] CONNECT response from the peer.
AsyncCall::Pointer closer
called when the connection is being closed
Definition: HttpTunneler.h:107
RefCount< AccessLogEntry > AccessLogEntryPointer
Definition: HttpTunneler.h:23
CBDATA_CLASS(Tunneler)
void handleResponse(const bool eof)
Parses [possibly incomplete] CONNECT response and reacts to it.
int conn
the current server connection FD
Definition: Transport.cc:26
bool tunnelEstablished
whether we got a 200 OK response
Definition: HttpTunneler.h:126
virtual const char * status() const
internal cleanup; do not call directly
AccessLogEntryPointer al
info for the future access.log entry
Definition: HttpTunneler.h:114
void handleConnectionClosure(const CommCloseCbParams &)
HttpRequestPointer request
peer connection trigger or cause
Definition: HttpTunneler.h:110
void callBack()
a bailWith(), sendSuccess() helper: sends results to the initiator
SBuf url
request-target for the CONNECT request
Definition: HttpTunneler.h:112
void handleWrittenRequest(const CommIoCbParams &)
Called when we are done writing a CONNECT request header to a peer.
void(Initiator::* Method)(Http::TunnelerAnswer &)
Definition: HttpTunneler.h:43
CbDialer(Method method, Initiator *initiator)
Definition: HttpTunneler.h:45
AsyncCall::Pointer callback
we call this with the results
Definition: HttpTunneler.h:111
virtual void swanSong()
void setDelayId(DelayId delay_id)
Definition: HttpTunneler.h:65
Tunneler(const Comm::ConnectionPointer &conn, const HttpRequestPointer &req, AsyncCall::Pointer &aCallback, time_t timeout, const AccessLogEntryPointer &alp)
Definition: HttpTunneler.cc:28
size_t HttpReply *STUB StoreEntry const KeyScope scope const HttpRequestMethod & method
Definition: stub_store.cc:105
virtual ~Tunneler()
Definition: HttpTunneler.cc:50
AsyncCall::Pointer writer
called when the request has been written
Definition: HttpTunneler.h:105
bool canDial(AsyncCall &)
Definition: HttpTunneler.h:49
Tunneler & operator=(const Tunneler &)=delete
bool noteFwdPconnUse
hack: whether the connection requires fwdPconnPool->noteUses()
Definition: HttpTunneler.h:69
Http1::ResponseParserPointer hp
Parser being used at present to parse the HTTP peer response.
Definition: HttpTunneler.h:121
TunnelerAnswer & answer()
convenience method to get to the answer fields
Definition: HttpTunneler.cc:63
void watchForClosures()
make sure we quit if/when the connection is gone
CbcPointer< Initiator > initiator_
object to deliver the answer to
Definition: HttpTunneler.h:55

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors