FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
easyhttpcpp/src/HttpRequestExecutor.cpp at master · sony/easyhttpcpp · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
sony
/
easyhttpcpp
Public
Notifications
You must be signed in to change notification settings
Fork
31
Star
176
Code
Issues
11
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
easyhttpcpp
/
src
/
HttpRequestExecutor.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
127 lines (105 loc) · 3.78 KB
Breadcrumbs
easyhttpcpp
/
src
/
HttpRequestExecutor.cpp
Copy path
File metadata and controls
127 lines (105 loc) · 3.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Copyright 2017 Sony Corporation
*/
#
include
"
easyhttpcpp/common/CoreLogger.h
"
#
include
"
easyhttpcpp/common/StringUtil.h
"
#
include
"
easyhttpcpp/HttpException.h
"
#
include
"
easyhttpcpp/Interceptor.h
"
#
include
"
CallInterceptorChain.h
"
#
include
"
HttpRequestExecutor.h
"
#
include
"
ResponseBodyStreamInternal.h
"
using
easyhttpcpp::common::StringUtil;
namespace
easyhttpcpp
{
static
const
std::string Tag =
"
HttpRequestExecutor
"
;
static
const
int
MaxRetryCount =
5
;
HttpRequestExecutor::HttpRequestExecutor
(EasyHttpContext::Ptr pContext, Request::Ptr pRequest) : m_pContext(pContext),
m_pUserRequest
(pRequest), m_cancelled(
false
)
{
}
HttpRequestExecutor::~HttpRequestExecutor
()
{
}
Response::Ptr
HttpRequestExecutor::execute
()
{
EasyHttpContext::InterceptorList& callInterceptors = m_pContext->
getCallInterceptors
();
EasyHttpContext::InterceptorList::iterator it = callInterceptors.
begin
();
EasyHttpContext::InterceptorList::const_iterator itEnd = callInterceptors.
end
();
if
(it == itEnd) {
return
executeWithRetry
(m_pUserRequest);
}
else
{
CallInterceptorChain::Ptr
chain
(
new
CallInterceptorChain
(
HttpRequestExecutor::Ptr
(
this
,
true
), m_pUserRequest,
it, itEnd));
return
(*it)->
intercept
(*chain);
}
}
Response::Ptr
HttpRequestExecutor::executeAfterIntercept
(Request::Ptr pRequest)
{
return
executeWithRetry
(pRequest);
}
bool
HttpRequestExecutor::cancel
()
{
Poco::FastMutex::ScopedLock
lock
(m_cancelMutex);
EASYHTTPCPP_LOG_D
(Tag,
"
cancel: cancelled
"
);
m_cancelled =
true
;
bool
ret =
true
;
if
(m_pHttpEngine) {
if
(!m_pHttpEngine->
cancel
()) {
ret =
false
;
}
}
if
(m_pUserResponse) {
ResponseBody::Ptr pResponseBody = m_pUserResponse->
getBody
();
if
(pResponseBody) {
ResponseBodyStream::Ptr pResponseBodyStream = pResponseBody->
getByteStream
();
if
(pResponseBodyStream) {
//
When call the ResponseBodyStream::close, ResponseBodyStream::read will fail.
//
If you have not read to the end, not also written to the cache.
EASYHTTPCPP_LOG_D
(Tag,
"
cancel: close stream
"
);
pResponseBodyStream->
close
();
}
}
}
return
ret;
}
bool
HttpRequestExecutor::isCancelled
()
const
{
return
m_cancelled;
}
HttpEngine::Ptr
HttpRequestExecutor::getHttpEngine
()
{
return
m_pHttpEngine;
}
Response::Ptr
HttpRequestExecutor::executeWithRetry
(Request::Ptr pRequest)
{
Response::Ptr pPriorResponse;
Request::Ptr pCurrentRequest = pRequest;
int
retryCount =
0
;
do
{
{
Poco::FastMutex::ScopedLock
lock
(m_cancelMutex);
if
(m_cancelled) {
EASYHTTPCPP_LOG_D
(Tag,
"
executeWithRetry: request is cancelled before create HttpEngine.
"
);
throw
HttpExecutionException
(
"
http request is cancelled.
"
);
}
m_pHttpEngine =
new
HttpEngine
(m_pContext, pCurrentRequest, pPriorResponse);
}
Response::Ptr pUserResponse = m_pHttpEngine->
execute
();
//
check retry
Request::Ptr pRetryRequest =
HttpEngine::getRetryRequest
(pUserResponse);
if
(pRetryRequest) {
m_pHttpEngine->
readAllResponseBodyForCache
(pUserResponse);
pPriorResponse = pUserResponse;
pCurrentRequest = pRetryRequest;
retryCount++;
continue
;
}
{
Poco::FastMutex::ScopedLock
lock
(m_cancelMutex);
m_pUserResponse = pUserResponse;
}
return
m_pUserResponse;
}
while
(retryCount <= MaxRetryCount);
EASYHTTPCPP_LOG_D
(Tag,
"
retry count over %d times.
"
, MaxRetryCount);
throw
HttpExecutionException
(
StringUtil::format
(
"
too many retry request. %d times.
"
, MaxRetryCount));
}
}
/*
namespace easyhttpcpp
*/
Back
|
FazBrowse Home
|
New Git URL