2 * Copyright (C) 1996-2023 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_SRC_DOWNLOADER_H
10 #define SQUID_SRC_DOWNLOADER_H
12 #include "base/AsyncCallbacks.h"
13 #include "base/AsyncJob.h"
15 #include "http/forward.h"
16 #include "http/StatusCode.h"
17 #include "sbuf/SBuf.h"
19 class ClientHttpRequest
;
21 class clientStreamNode
;
22 class DownloaderContext
;
23 typedef RefCount
<DownloaderContext
> DownloaderContextPointer
;
25 using MasterXactionPointer
= RefCount
<MasterXaction
>;
28 class DownloaderAnswer
{
30 // The content of a successfully received HTTP 200 OK reply to our GET request.
31 // Unused unless outcome is Http::scOkay.
34 /// Download result summary.
35 /// May differ from the status code of the downloaded HTTP reply.
36 Http::StatusCode outcome
= Http::scNone
;
39 std::ostream
&operator <<(std::ostream
&, const DownloaderAnswer
&);
41 /// The Downloader class fetches SBuf-storable things for other Squid
42 /// components/transactions using internal requests. For example, it is used
43 /// to fetch missing intermediate certificates when validating origin server
44 /// certificate chains.
45 class Downloader
: virtual public AsyncJob
47 CBDATA_CHILD(Downloader
);
49 using Answer
= DownloaderAnswer
;
51 Downloader(const SBuf
&url
, const AsyncCallback
<Answer
> &, const MasterXactionPointer
&, unsigned int level
= 0);
52 ~Downloader() override
;
53 void swanSong() override
;
55 /// delays destruction to protect doCallouts()
56 void downloadFinished();
58 /// The nested level of Downloader object (downloads inside downloads).
59 unsigned int nestedLevel() const {return level_
;}
61 void handleReply(clientStreamNode
*, ClientHttpRequest
*, HttpReply
*, StoreIOBuffer
);
66 bool doneAll() const override
;
67 void start() override
;
72 void callBack(Http::StatusCode
const status
);
74 /// The maximum allowed object size.
75 static const size_t MaxObjectSize
= 1*1024*1024;
77 SBuf url_
; ///< the url to download
79 /// answer destination
80 AsyncCallback
<Answer
> callback_
;
82 SBuf object_
; ///< the object body data
83 const unsigned int level_
; ///< holds the nested downloads level
84 MasterXactionPointer masterXaction_
; ///< download transaction context
86 /// Pointer to an object that stores the clientStream required info
87 DownloaderContextPointer context_
;
90 #endif /* SQUID_SRC_DOWNLOADER_H */