HttpTunneler.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_SRC_CLIENTS_HTTP_TUNNELER_H
10#define SQUID_SRC_CLIENTS_HTTP_TUNNELER_H
11
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
22class ErrorState;
23class AccessLogEntry;
25
26namespace Http
27{
28
32class Tunneler: virtual public AsyncJob
33{
35
36public:
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
59public:
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
71protected:
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();
83 void writeRequest();
86 void readMore();
87 void handleResponse(const bool eof);
88 void bailOnResponseError(const char *error, HttpReply *);
89
90private:
92 void bailWith(ErrorState*);
93
95 void sendSuccess();
96
98 void callBack();
99
101 void disconnect();
102
105
107
111
118#if USE_DELAY_POOLS
120#endif
121
125
126 const time_t startTime;
127
130};
131
132} // namespace Http
133
134#endif /* SQUID_SRC_CLIENTS_HTTP_TUNNELER_H */
135
RefCount< AccessLogEntry > AccessLogEntryPointer
Definition: HttpTunneler.h:24
int conn
the current server connection FD
Definition: Transport.cc:26
void error(char *format,...)
Cbc * valid() const
was set and is valid
Definition: CbcPointer.h:41
Callback dialer API to allow Tunneler to set the answer.
Definition: HttpTunneler.h:40
virtual void print(std::ostream &os) const override
Definition: HttpTunneler.h:51
void dial(AsyncCall &)
Definition: HttpTunneler.h:50
void(Initiator::* Method)(Http::TunnelerAnswer &)
Definition: HttpTunneler.h:43
virtual ~CbDialer()=default
CbcPointer< Initiator > initiator_
object to deliver the answer to
Definition: HttpTunneler.h:55
CbDialer(Method method, Initiator *initiator)
Definition: HttpTunneler.h:45
Method method_
initiator_ method to call with the answer
Definition: HttpTunneler.h:56
bool canDial(AsyncCall &)
Definition: HttpTunneler.h:49
void countFailingConnection()
updates connection usage history before the connection is closed
void disconnect()
stops monitoring the connection
void bailOnResponseError(const char *error, HttpReply *)
const time_t startTime
when the tunnel establishment started
Definition: HttpTunneler.h:126
Tunneler(const Tunneler &)=delete
void handleResponse(const bool eof)
Parses [possibly incomplete] CONNECT response and reacts to it.
CBDATA_CLASS(Tunneler)
void callBack()
a bailWith(), sendSuccess() helper: sends results to the initiator
void bailWith(ErrorState *)
sends the given error to the initiator
bool tunnelEstablished
whether we got a 200 OK response
Definition: HttpTunneler.h:129
void handleConnectionClosure(const CommCloseCbParams &)
virtual void start()
called by AsyncStart; do not call directly
Definition: HttpTunneler.cc:73
virtual const char * status() const
internal cleanup; do not call directly
AsyncCall::Pointer closer
called when the connection is being closed
Definition: HttpTunneler.h:110
void handleWrittenRequest(const CommIoCbParams &)
Called when we are done writing a CONNECT request header to a peer.
virtual bool doneAll() const
whether positive goal has been reached
Definition: HttpTunneler.cc:57
time_t lifetimeLimit
do not run longer than this
Definition: HttpTunneler.h:116
void watchForClosures()
make sure we quit if/when the connection is gone
Tunneler(const Comm::ConnectionPointer &conn, const HttpRequestPointer &req, AsyncCall::Pointer &aCallback, time_t timeout, const AccessLogEntryPointer &alp)
Definition: HttpTunneler.cc:29
void setDelayId(DelayId delay_id)
Definition: HttpTunneler.h:65
AsyncCall::Pointer callback
we call this with the results
Definition: HttpTunneler.h:114
AsyncCall::Pointer reader
called when the response should be read
Definition: HttpTunneler.h:109
bool requestWritten
whether we successfully wrote the request
Definition: HttpTunneler.h:128
void sendSuccess()
sends the ready-to-use tunnel to the initiator
AsyncCall::Pointer writer
called when the request has been written
Definition: HttpTunneler.h:108
virtual void swanSong()
AccessLogEntryPointer al
info for the future access.log entry
Definition: HttpTunneler.h:117
void startReadingResponse()
bool noteFwdPconnUse
hack: whether the connection requires fwdPconnPool->noteUses()
Definition: HttpTunneler.h:69
virtual ~Tunneler()
Definition: HttpTunneler.cc:51
SBuf url
request-target for the CONNECT request
Definition: HttpTunneler.h:115
HttpRequestPointer request
peer connection trigger or cause
Definition: HttpTunneler.h:113
void handleTimeout(const CommTimeoutCbParams &)
The connection read timeout callback handler.
TunnelerAnswer & answer()
convenience method to get to the answer fields
Definition: HttpTunneler.cc:64
Tunneler & operator=(const Tunneler &)=delete
void handleReadyRead(const CommIoCbParams &)
Called when we read [a part of] CONNECT response from the peer.
Http1::ResponseParserPointer hp
Parser being used at present to parse the HTTP peer response.
Definition: HttpTunneler.h:124
Comm::ConnectionPointer connection
TCP connection to the cache_peer.
Definition: HttpTunneler.h:112
Definition: SBuf.h:94
Definition: forward.h:22

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors