]> git.ipfire.org Git - thirdparty/squid.git/blob - src/Downloader.h
NoNewGlobals for MapLabel (#1746)
[thirdparty/squid.git] / src / Downloader.h
1 /*
2 * Copyright (C) 1996-2023 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_DOWNLOADER_H
10 #define SQUID_SRC_DOWNLOADER_H
11
12 #include "base/AsyncCallbacks.h"
13 #include "base/AsyncJob.h"
14 #include "defines.h"
15 #include "http/forward.h"
16 #include "http/StatusCode.h"
17 #include "sbuf/SBuf.h"
18
19 class ClientHttpRequest;
20 class StoreIOBuffer;
21 class clientStreamNode;
22 class DownloaderContext;
23 typedef RefCount<DownloaderContext> DownloaderContextPointer;
24 class MasterXaction;
25 using MasterXactionPointer = RefCount<MasterXaction>;
26
27 /// download result
28 class DownloaderAnswer {
29 public:
30 // The content of a successfully received HTTP 200 OK reply to our GET request.
31 // Unused unless outcome is Http::scOkay.
32 SBuf resource;
33
34 /// Download result summary.
35 /// May differ from the status code of the downloaded HTTP reply.
36 Http::StatusCode outcome = Http::scNone;
37 };
38
39 std::ostream &operator <<(std::ostream &, const DownloaderAnswer &);
40
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
46 {
47 CBDATA_CHILD(Downloader);
48 public:
49 using Answer = DownloaderAnswer;
50
51 Downloader(const SBuf &url, const AsyncCallback<Answer> &, const MasterXactionPointer &, unsigned int level = 0);
52 ~Downloader() override;
53 void swanSong() override;
54
55 /// delays destruction to protect doCallouts()
56 void downloadFinished();
57
58 /// The nested level of Downloader object (downloads inside downloads).
59 unsigned int nestedLevel() const {return level_;}
60
61 void handleReply(clientStreamNode *, ClientHttpRequest *, HttpReply *, StoreIOBuffer);
62
63 protected:
64
65 /* AsyncJob API */
66 bool doneAll() const override;
67 void start() override;
68
69 private:
70
71 bool buildRequest();
72 void callBack(Http::StatusCode const status);
73
74 /// The maximum allowed object size.
75 static const size_t MaxObjectSize = 1*1024*1024;
76
77 SBuf url_; ///< the url to download
78
79 /// answer destination
80 AsyncCallback<Answer> callback_;
81
82 SBuf object_; ///< the object body data
83 const unsigned int level_; ///< holds the nested downloads level
84 MasterXactionPointer masterXaction_; ///< download transaction context
85
86 /// Pointer to an object that stores the clientStream required info
87 DownloaderContextPointer context_;
88 };
89
90 #endif /* SQUID_SRC_DOWNLOADER_H */
91