1#include "cpr/interceptor.h"
2
3#include <exception>
4
5namespace cpr {
6
7Response Interceptor::proceed(Session& session) {
8 return session.proceed();
9}
10
11Response Interceptor::proceed(Session& session, ProceedHttpMethod httpMethod) {
12 switch (httpMethod) {
13 case ProceedHttpMethod::DELETE_REQUEST:
14 return session.Delete();
15 case ProceedHttpMethod::GET_REQUEST:
16 return session.Get();
17 case ProceedHttpMethod::HEAD_REQUEST:
18 return session.Head();
19 case ProceedHttpMethod::OPTIONS_REQUEST:
20 return session.Options();
21 case ProceedHttpMethod::PATCH_REQUEST:
22 return session.Patch();
23 case ProceedHttpMethod::POST_REQUEST:
24 return session.Post();
25 case ProceedHttpMethod::PUT_REQUEST:
26 return session.Put();
27 default:
28 throw std::invalid_argument{"Can't proceed the session with the provided http method!"};
29 }
30}
31
32Response Interceptor::proceed(Session& session, ProceedHttpMethod httpMethod, std::ofstream& file) {
33 if (httpMethod == ProceedHttpMethod::DOWNLOAD_FILE_REQUEST) {
34 return session.Download(file);
35 }
36 throw std::invalid_argument{"std::ofstream argument is only valid for ProceedHttpMethod::DOWNLOAD_FILE!"};
37}
38
39Response Interceptor::proceed(Session& session, ProceedHttpMethod httpMethod, const WriteCallback& write) {
40 if (httpMethod == ProceedHttpMethod::DOWNLOAD_CALLBACK_REQUEST) {
41 return session.Download(write);
42 }
43 throw std::invalid_argument{"WriteCallback argument is only valid for ProceedHttpMethod::DOWNLOAD_CALLBACK!"};
44}
45
46std::vector<Response> InterceptorMulti::proceed(MultiPerform& multi) {
47 return multi.proceed();
48}
49
50void InterceptorMulti::PrepareDownloadSession(MultiPerform& multi, size_t sessions_index, const WriteCallback& write) {
51 multi.PrepareDownloadSessions(sessions_index, current_arg: write);
52}
53} // namespace cpr