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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors