]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpRequest.h
author: Eduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
[thirdparty/squid.git] / src / HttpRequest.h
CommitLineData
528b2c61 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
528b2c61 3 *
bbc27441
AJ
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.
528b2c61 7 */
8
9#ifndef SQUID_HTTPREQUEST_H
10#define SQUID_HTTPREQUEST_H
11
582c2af2 12#include "base/CbcPointer.h"
4a3b98d7 13#include "dns/forward.h"
c8f1812b 14#include "err_type.h"
582c2af2 15#include "HierarchyLogEntry.h"
f35c0145 16#include "http/RequestMethod.h"
e74be5fd 17#include "HttpMsg.h"
d06e17ea 18#include "Notes.h"
f206b652 19#include "RequestFlags.h"
4e3f4dc7 20#include "URL.h"
582c2af2
FC
21
22#if USE_AUTH
23#include "auth/UserRequest.h"
24#endif
3ff65596
AR
25#if USE_ADAPTATION
26#include "adaptation/History.h"
27#endif
28#if ICAP_CLIENT
29#include "adaptation/icap/History.h"
30#endif
a98c2da5
AJ
31#if USE_SQUID_EUI
32#include "eui/Eui48.h"
33#include "eui/Eui64.h"
34#endif
582c2af2
FC
35
36class ConnStateData;
cda7024f 37class Downloader;
a2ac85d9 38
924f73bc 39/* Http Request */
17802cf1 40void httpRequestPack(void *obj, Packable *p);
5cafad19 41
924f73bc 42class HttpHdrRange;
43
8596962e 44class HttpRequest: public HttpMsg
a2ac85d9 45{
741c2986 46 MEMPROXY_CLASS(HttpRequest);
a2ac85d9 47
48public:
b248c2a3 49 typedef RefCount<HttpRequest> Pointer;
f3630c67 50
75faaa7a 51 HttpRequest();
d31d59d8 52 HttpRequest(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *schemeImage, const char *aUrlpath);
5cafad19 53 ~HttpRequest();
8596962e 54 virtual void reset();
4a56ee8d 55
d31d59d8 56 void initHTTP(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *schemeImage, const char *aUrlpath);
75faaa7a 57
fa0e6114
AR
58 virtual HttpRequest *clone() const;
59
c2a7cefd
AJ
60 /// Whether response to this request is potentially cachable
61 /// \retval false Not cacheable.
62 /// \retval true Possibly cacheable. Response factors will determine.
63 bool maybeCacheable();
610ee341 64
79c8035e
AR
65 bool conditional() const; ///< has at least one recognized If-* header
66
655daa06
AR
67 /// whether the client is likely to be able to handle a 1xx reply
68 bool canHandle1xx() const;
69
3ff65596
AR
70#if USE_ADAPTATION
71 /// Returns possibly nil history, creating it if adapt. logging is enabled
a22e6cd3
AR
72 Adaptation::History::Pointer adaptLogHistory() const;
73 /// Returns possibly nil history, creating it if requested
74 Adaptation::History::Pointer adaptHistory(bool createIfNone = false) const;
aaf0559d
AR
75 /// Makes their history ours, throwing on conflicts
76 void adaptHistoryImport(const HttpRequest &them);
3ff65596
AR
77#endif
78#if ICAP_CLIENT
79 /// Returns possibly nil history, creating it if icap logging is enabled
80 Adaptation::Icap::History::Pointer icapHistory() const;
81#endif
82
4a3b98d7 83 void recordLookup(const Dns::LookupDetails &detail);
3ff65596 84
64b66b76
CT
85 /// sets error detail if no earlier detail was available
86 void detailError(err_type aType, int aDetail);
129fe2a1
CT
87 /// clear error details, useful for retries/repeats
88 void clearError();
64b66b76 89
5cafad19 90protected:
5cafad19 91 void clean();
5cafad19 92
4a56ee8d 93 void init();
a2ac85d9 94
5cafad19 95public:
60745f24 96 HttpRequestMethod method;
5c51bffb 97 URL url; ///< the request URI
4a56ee8d 98
cc192b50 99private:
3ff65596
AR
100#if USE_ADAPTATION
101 mutable Adaptation::History::Pointer adaptHistory_; ///< per-HTTP transaction info
102#endif
103#if ICAP_CLIENT
104 mutable Adaptation::Icap::History::Pointer icapHistory_; ///< per-HTTP transaction info
105#endif
106
cc192b50 107public:
2f1431ea 108#if USE_AUTH
c7baff40 109 Auth::UserRequest::Pointer auth_user_request;
2f1431ea 110#endif
4a56ee8d 111
851feda6
AJ
112 /// RFC 7230 section 5.5 - Effective Request URI
113 const SBuf &effectiveRequestUri() const;
4a56ee8d 114
a8a0b1c2
EC
115 /**
116 * If defined, store_id_program mapped the request URL to this ID.
117 * Store uses this ID (and not the URL) to find and store entries,
118 * avoiding caching duplicate entries when different URLs point to
119 * "essentially the same" cachable resource.
120 */
121 String store_id;
122
f206b652 123 RequestFlags flags;
4a56ee8d 124
a2ac85d9 125 HttpHdrRange *range;
4a56ee8d 126
a2ac85d9 127 time_t ims;
4a56ee8d 128
a2ac85d9 129 int imslen;
4a56ee8d 130
b7ac5457 131 Ip::Address client_addr;
4a56ee8d 132
33b24cf0 133#if FOLLOW_X_FORWARDED_FOR
b7ac5457 134 Ip::Address indirect_client_addr;
33b24cf0 135#endif /* FOLLOW_X_FORWARDED_FOR */
3d674977 136
b7ac5457 137 Ip::Address my_addr;
4a56ee8d 138
a2ac85d9 139 HierarchyLogEntry hier;
4a56ee8d 140
3ff65596
AR
141 int dnsWait; ///< sum of DNS lookup delays in milliseconds, for %dt
142
a2ac85d9 143 err_type errType;
64b66b76 144 int errDetail; ///< errType-specific detail about the transaction error
4a56ee8d 145
f53969cc 146 char *peer_login; /* Configured peer login:password */
4a56ee8d 147
9ca29d23
AJ
148 char *peer_host; /* Selected peer host*/
149
f53969cc 150 time_t lastmod; /* Used on refreshes */
4a56ee8d 151
90ab8f20
AJ
152 /// The variant second-stage cache key. Generated from Vary header pattern for this request.
153 SBuf vary_headers;
4a56ee8d 154
f53969cc 155 char *peer_domain; /* Configured peer forceddomain */
4a56ee8d 156
35fb56c9
AJ
157 String myportname; // Internal tag name= value from port this requests arrived in.
158
f53969cc 159 String tag; /* Internal tag for this request */
4a56ee8d 160
f53969cc 161 String extacl_user; /* User name returned by extacl lookup */
4a56ee8d 162
f53969cc 163 String extacl_passwd; /* Password returned by extacl lookup */
4a56ee8d 164
f53969cc 165 String extacl_log; /* String to be used for access.log purposes */
8596962e 166
f53969cc 167 String extacl_message; /* String to be used for error page purposes */
8c93a598 168
33b24cf0 169#if FOLLOW_X_FORWARDED_FOR
3d674977 170 String x_forwarded_for_iterator; /* XXX a list of IP addresses */
33b24cf0 171#endif /* FOLLOW_X_FORWARDED_FOR */
3d674977 172
46017fdd
CT
173 /// A strong etag of the cached entry. Used for refreshing that entry.
174 String etag;
175
ec69bdb2
CT
176 /// whether we have responded with HTTP 100 or FTP 150 already
177 bool forcedBodyContinuation;
178
8596962e 179public:
5cafad19 180 bool multipartRangeRequest() const;
4a56ee8d 181
429f7150 182 bool parseFirstLine(const char *start, const char *end);
4a56ee8d 183
60745f24 184 virtual bool expectingBody(const HttpRequestMethod& unused, int64_t&) const;
4a56ee8d 185
58217e94 186 bool bodyNibbled() const; // the request has a [partially] consumed body
187
51b5dcf5 188 int prefixLen() const;
4a56ee8d 189
5cafad19 190 void swapOut(StoreEntry * e);
4a56ee8d 191
1f28a150 192 void pack(Packable * p) const;
4a56ee8d 193
17802cf1 194 static void httpRequestPack(void *obj, Packable *p);
8596962e 195
d6067ac1 196 static HttpRequest * CreateFromUrl(char * url, const HttpRequestMethod &method = Http::METHOD_GET);
26ac0430 197
582c2af2 198 ConnStateData *pinnedConnection();
d67acb4e 199
a8a0b1c2
EC
200 /**
201 * Returns the current StoreID for the request as a nul-terminated char*.
202 * Always returns the current id for the request
851feda6 203 * (either the effective request URI or modified ID by the helper).
a8a0b1c2 204 */
851feda6 205 const SBuf storeId();
a8a0b1c2 206
b1cf2350
AJ
207 /**
208 * The client connection manager, if known;
209 * Used for any response actions needed directly to the client.
210 * ie 1xx forwarding or connection pinning state changes
211 */
40d34a62 212 CbcPointer<ConnStateData> clientConnectionManager;
655daa06 213
4b5ea8a6 214 /// The Downloader object which initiated the HTTP request if any
cda7024f
CT
215 CbcPointer<Downloader> downloader;
216
f0baf149
AR
217 /// forgets about the cached Range header (for a reason)
218 void ignoreRange(const char *reason);
11e3fa1c
AJ
219 int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */
220
75d47340
CT
221 /// \returns existing non-empty transaction annotations,
222 /// creates and returns empty annotations otherwise
223 NotePairs::Pointer notes();
224 bool hasNotes() const { return bool(theNotes) && !theNotes->empty(); }
225
8596962e 226private:
11e3fa1c
AJ
227 mutable int64_t rangeOffsetLimit; /* caches the result of getRangeOffsetLimit */
228
75d47340
CT
229 /// annotations added by the note directive and helpers
230 /// and(or) by annotate_transaction/annotate_client ACLs.
231 NotePairs::Pointer theNotes;
8596962e 232protected:
17802cf1 233 virtual void packFirstLineInto(Packable * p, bool full_uri) const;
4a56ee8d 234
84ae6223 235 virtual bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error);
4a56ee8d 236
07947ad8 237 virtual void hdrCacheInit();
26ac0430 238
d67acb4e 239 virtual bool inheritProperties(const HttpMsg *aMsg);
a2ac85d9 240};
528b2c61 241
75d47340
CT
242class ConnStateData;
243/**
244 * Updates ConnStateData ids and HttpRequest notes from helpers received notes.
245 */
246void UpdateRequestNotes(ConnStateData *csd, HttpRequest &request, NotePairs const &notes);
247
528b2c61 248#endif /* SQUID_HTTPREQUEST_H */
f53969cc 249