]>
Commit | Line | Data |
---|---|---|
4b5ea8a6 | 1 | /* |
bf95c10a | 2 | * Copyright (C) 1996-2022 The Squid Software Foundation and contributors |
4b5ea8a6 CT |
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 | ||
55369ae6 AR |
9 | #ifndef SQUID_DOWNLOADER_H |
10 | #define SQUID_DOWNLOADER_H | |
11 | ||
e5ddd4ce | 12 | #include "base/AsyncCallbacks.h" |
cda7024f | 13 | #include "base/AsyncJob.h" |
cda7024f | 14 | #include "defines.h" |
4b5ea8a6 | 15 | #include "http/forward.h" |
cda7024f CT |
16 | #include "http/StatusCode.h" |
17 | #include "sbuf/SBuf.h" | |
55369ae6 | 18 | |
cda7024f CT |
19 | class ClientHttpRequest; |
20 | class StoreIOBuffer; | |
21 | class clientStreamNode; | |
a175ef71 CT |
22 | class DownloaderContext; |
23 | typedef RefCount<DownloaderContext> DownloaderContextPointer; | |
ad05b958 EB |
24 | class MasterXaction; |
25 | using MasterXactionPointer = RefCount<MasterXaction>; | |
cda7024f | 26 | |
e5ddd4ce AR |
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 | ||
a175ef71 CT |
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. | |
cda7024f | 45 | class Downloader: virtual public AsyncJob |
55369ae6 | 46 | { |
337b9aa4 | 47 | CBDATA_CHILD(Downloader); |
55369ae6 | 48 | public: |
e5ddd4ce | 49 | using Answer = DownloaderAnswer; |
6cae08c9 | 50 | |
e5ddd4ce | 51 | Downloader(const SBuf &url, const AsyncCallback<Answer> &, const MasterXactionPointer &, unsigned int level = 0); |
337b9aa4 AR |
52 | ~Downloader() override; |
53 | void swanSong() override; | |
6cae08c9 | 54 | |
4b5ea8a6 | 55 | /// delays destruction to protect doCallouts() |
55369ae6 | 56 | void downloadFinished(); |
4e526b93 | 57 | |
168d2b30 | 58 | /// The nested level of Downloader object (downloads inside downloads). |
4e526b93 | 59 | unsigned int nestedLevel() const {return level_;} |
3945c91d | 60 | |
4b5ea8a6 | 61 | void handleReply(clientStreamNode *, ClientHttpRequest *, HttpReply *, StoreIOBuffer); |
55369ae6 | 62 | |
55369ae6 | 63 | protected: |
55369ae6 AR |
64 | |
65 | /* AsyncJob API */ | |
337b9aa4 AR |
66 | bool doneAll() const override; |
67 | void start() override; | |
55369ae6 AR |
68 | |
69 | private: | |
cda7024f CT |
70 | |
71 | bool buildRequest(); | |
4b5ea8a6 | 72 | void callBack(Http::StatusCode const status); |
6cae08c9 | 73 | |
168d2b30 CT |
74 | /// The maximum allowed object size. |
75 | static const size_t MaxObjectSize = 1*1024*1024; | |
6cae08c9 | 76 | |
168d2b30 | 77 | SBuf url_; ///< the url to download |
e5ddd4ce AR |
78 | |
79 | /// answer destination | |
80 | AsyncCallback<Answer> callback_; | |
81 | ||
4b5ea8a6 | 82 | SBuf object_; ///< the object body data |
a175ef71 | 83 | const unsigned int level_; ///< holds the nested downloads level |
ad05b958 | 84 | MasterXactionPointer masterXaction_; ///< download transaction context |
cda7024f | 85 | |
a175ef71 CT |
86 | /// Pointer to an object that stores the clientStream required info |
87 | DownloaderContextPointer context_; | |
55369ae6 AR |
88 | }; |
89 | ||
90 | #endif | |
3945c91d | 91 |