2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_CLIENTSIDEREPLY_H
10 #define SQUID_CLIENTSIDEREPLY_H
12 #include "acl/forward.h"
13 #include "client_side_request.h"
14 #include "ip/forward.h"
15 #include "RequestFlags.h"
16 #include "StoreClient.h"
20 /* XXX make static method */
22 class clientReplyContext
: public RefCountable
, public StoreClient
24 CBDATA_CLASS(clientReplyContext
);
28 static STCB HandleIMSReply
;
29 static STCB SendMoreData
;
31 clientReplyContext(ClientHttpRequest
*);
32 ~clientReplyContext();
37 void purgeRequestFindObjectToPurge();
38 void purgeDoMissPurge();
39 void purgeFoundGet(StoreEntry
*newEntry
);
40 void purgeFoundHead(StoreEntry
*newEntry
);
41 void purgeFoundObject(StoreEntry
*entry
);
42 void sendClientUpstreamResponse();
43 void purgeDoPurgeGet(StoreEntry
*entry
);
44 void purgeDoPurgeHead(StoreEntry
*entry
);
46 void identifyStoreObject();
47 void identifyFoundObject(StoreEntry
*entry
);
48 int storeOKTransferDone() const;
49 int storeNotOKTransferDone() const;
50 /// replaces current response store entry with the given one
51 void setReplyToStoreEntry(StoreEntry
*e
, const char *reason
);
52 /// builds error using clientBuildError() and calls setReplyToError() below
53 void setReplyToError(err_type
, Http::StatusCode
, const HttpRequestMethod
&, char const *, Ip::Address
&, HttpRequest
*, const char *,
55 Auth::UserRequest::Pointer
);
59 /// creates a store entry for the reply and appends err to it
60 void setReplyToError(const HttpRequestMethod
& method
, ErrorState
*err
);
61 /// creates a store entry for the reply and appends error reply to it
62 void setReplyToReply(HttpReply
*reply
);
63 void createStoreEntry(const HttpRequestMethod
& m
, RequestFlags flags
);
64 void removeStoreReference(store_client
** scp
, StoreEntry
** ep
);
65 void removeClientStoreReference(store_client
**scp
, ClientHttpRequest
*http
);
66 void startError(ErrorState
* err
);
67 void processExpired();
68 clientStream_status_t
replyStatus();
70 void traceReply(clientStreamNode
* node
);
71 const char *storeId() const { return (http
->store_id
.size() > 0 ? http
->store_id
.termedBuf() : http
->uri
); }
73 Http::StatusCode purgeStatus
;
75 /* state variable - replace with class to handle storeentries at some point */
77 virtual void created (StoreEntry
*newEntry
);
79 ClientHttpRequest
*http
;
81 store_client
*sc
; /* The store_client we're using */
82 StoreIOBuffer tempBuffer
; /* For use in validating requests via IMS */
83 int old_reqsize
; /* ... again, for the buffer */
86 char tempbuf
[HTTP_REQBUF_SZ
]; ///< a temporary buffer if we need working storage
89 const char *lookup_type
; /* temporary hack: storeGet() result: HIT/MISS/NONE */
93 Flags() : storelogiccomplete(0), complete(0), headersSent(false) {}
95 unsigned storelogiccomplete
:1;
96 unsigned complete
:1; ///< we have read all we can from upstream
99 clientStreamNode
*ourNode
; /* This will go away if/when this file gets refactored some more */
102 clientStreamNode
*getNextNode() const;
104 bool errorInStream(StoreIOBuffer
const &result
, size_t const &sizeToProcess
)const ;
105 void sendStreamError(StoreIOBuffer
const &result
);
106 void pushStreamData(StoreIOBuffer
const &result
, char *source
);
107 clientStreamNode
* next() const;
108 StoreIOBuffer holdingBuffer
;
110 void processReplyAccess();
111 static ACLCB ProcessReplyAccessResult
;
112 void processReplyAccessResult(const allow_t
&accessAllowed
);
114 void buildReplyHeader ();
115 bool alwaysAllowResponse(Http::StatusCode sline
) const;
116 int checkTransferDone();
117 void processOnlyIfCachedMiss();
118 void processConditional(StoreIOBuffer
&result
);
119 void cacheHit(StoreIOBuffer result
);
120 void handleIMSReply(StoreIOBuffer result
);
121 void sendMoreData(StoreIOBuffer result
);
122 void triggerInitialStoreRead();
123 void sendClientOldEntry();
124 void purgeAllCached();
126 bool blockedHit() const;
128 void sendBodyTooLargeError();
129 void sendPreconditionFailedError();
130 void sendNotModified();
131 void sendNotModifiedOrPreconditionFailedError();
133 StoreEntry
*old_entry
;
134 store_client
*old_sc
; /* ... for entry to be validated */
138 #endif /* SQUID_CLIENTSIDEREPLY_H */