| 1 | #ifndef CPR_INTERCEPTOR_H |
| 2 | #define CPR_INTERCEPTOR_H |
| 3 | |
| 4 | #include "cpr/multiperform.h" |
| 5 | #include "cpr/response.h" |
| 6 | #include "cpr/session.h" |
| 7 | #include <vector> |
| 8 | |
| 9 | namespace cpr { |
| 10 | class Interceptor { |
| 11 | public: |
| 12 | enum class ProceedHttpMethod { |
| 13 | GET_REQUEST = 0, |
| 14 | POST_REQUEST, |
| 15 | PUT_REQUEST, |
| 16 | DELETE_REQUEST, |
| 17 | PATCH_REQUEST, |
| 18 | HEAD_REQUEST, |
| 19 | OPTIONS_REQUEST, |
| 20 | DOWNLOAD_CALLBACK_REQUEST, |
| 21 | DOWNLOAD_FILE_REQUEST, |
| 22 | }; |
| 23 | |
| 24 | Interceptor() = default; |
| 25 | Interceptor(const Interceptor& other) = default; |
| 26 | Interceptor(Interceptor&& old) = default; |
| 27 | virtual ~Interceptor() = default; |
| 28 | |
| 29 | Interceptor& operator=(const Interceptor& other) = default; |
| 30 | Interceptor& operator=(Interceptor&& old) = default; |
| 31 | |
| 32 | virtual Response intercept(Session& session) = 0; |
| 33 | |
| 34 | protected: |
| 35 | static Response proceed(Session& session); |
| 36 | static Response proceed(Session& session, ProceedHttpMethod httpMethod); |
| 37 | static Response proceed(Session& session, ProceedHttpMethod httpMethod, std::ofstream& file); |
| 38 | static Response proceed(Session& session, ProceedHttpMethod httpMethod, const WriteCallback& write); |
| 39 | }; |
| 40 | |
| 41 | class InterceptorMulti { |
| 42 | public: |
| 43 | enum class ProceedHttpMethod { |
| 44 | GET_REQUEST = 0, |
| 45 | POST_REQUEST, |
| 46 | PUT_REQUEST, |
| 47 | DELETE_REQUEST, |
| 48 | PATCH_REQUEST, |
| 49 | HEAD_REQUEST, |
| 50 | OPTIONS_REQUEST, |
| 51 | DOWNLOAD_CALLBACK_REQUEST, |
| 52 | DOWNLOAD_FILE_REQUEST, |
| 53 | }; |
| 54 | |
| 55 | InterceptorMulti() = default; |
| 56 | InterceptorMulti(const InterceptorMulti& other) = default; |
| 57 | InterceptorMulti(InterceptorMulti&& old) = default; |
| 58 | virtual ~InterceptorMulti() = default; |
| 59 | |
| 60 | InterceptorMulti& operator=(const InterceptorMulti& other) = default; |
| 61 | InterceptorMulti& operator=(InterceptorMulti&& old) = default; |
| 62 | |
| 63 | virtual std::vector<Response> intercept(MultiPerform& multi) = 0; |
| 64 | |
| 65 | protected: |
| 66 | static std::vector<Response> proceed(MultiPerform& multi); |
| 67 | |
| 68 | static void PrepareDownloadSession(MultiPerform& multi, size_t sessions_index, const WriteCallback& write); |
| 69 | }; |
| 70 | |
| 71 | } // namespace cpr |
| 72 | |
| 73 | |
| 74 | #endif |