Skip to content

Commit 846c706

Browse files
committed
add http interceptor
1 parent 3aa7aa0 commit 846c706

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

sdk/include/alibabacloud/oss/client/ClientConfiguration.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <alibabacloud/oss/Types.h>
2121
#include <alibabacloud/oss/auth/CredentialsProvider.h>
2222
#include <alibabacloud/oss/http/HttpClient.h>
23+
#include <alibabacloud/oss/http/HttpInterceptor.h>
2324
#include <alibabacloud/oss/utils/Executor.h>
2425

2526
namespace AlibabaCloud
@@ -135,6 +136,11 @@ namespace OSS
135136
* signature version. default is V1.
136137
*/
137138
SignatureVersionType signatureVersion;
139+
140+
/**
141+
* Your http interceptor implement
142+
*/
143+
std::shared_ptr<HttpInterceptor> httpInterceptor;
138144
};
139145
}
140146
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <string>
20+
#include <alibabacloud/oss/Export.h>
21+
#include <alibabacloud/oss/http/HttpRequest.h>
22+
23+
namespace AlibabaCloud
24+
{
25+
namespace OSS
26+
{
27+
class ALIBABACLOUD_OSS_EXPORT HttpInterceptor
28+
{
29+
public:
30+
HttpInterceptor() = default;
31+
virtual ~HttpInterceptor() = default;
32+
virtual void preSendRequest(void *handler, const std::shared_ptr<HttpRequest> &request) = 0;
33+
};
34+
}
35+
}

sdk/src/client/ClientConfiguration.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ ClientConfiguration::ClientConfiguration() :
118118
httpClient(nullptr),
119119
isPathStyle(false),
120120
isVerifyObjectStrict(true),
121-
signatureVersion(SignatureVersionType::V1)
121+
signatureVersion(SignatureVersionType::V1),
122+
httpInterceptor(nullptr)
122123
{
123124

124125
}

sdk/src/http/CurlHttpClient.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ CurlHttpClient::CurlHttpClient(const ClientConfiguration &configuration) :
418418
caFile_(configuration.caFile),
419419
networkInterface_(configuration.networkInterface),
420420
sendRateLimiter_(configuration.sendRateLimiter),
421-
recvRateLimiter_(configuration.recvRateLimiter)
421+
recvRateLimiter_(configuration.recvRateLimiter),
422+
httpInterceptor_(configuration.httpInterceptor)
422423
{
423424
}
424425

@@ -567,6 +568,10 @@ std::shared_ptr<HttpResponse> CurlHttpClient::makeRequest(const std::shared_ptr<
567568
curl_easy_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE, speed);
568569
}
569570

571+
if (httpInterceptor_ != nullptr) {
572+
httpInterceptor_->preSendRequest(curl, request);
573+
}
574+
570575
CURLcode res = curl_easy_perform(curl);
571576
long response_code= 0;
572577
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);

sdk/src/http/CurlHttpClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ namespace OSS
5252
public:
5353
std::shared_ptr<RateLimiter> sendRateLimiter_;
5454
std::shared_ptr<RateLimiter> recvRateLimiter_;
55+
std::shared_ptr<HttpInterceptor> httpInterceptor_;
5556
};
5657
}
5758
}

0 commit comments

Comments
 (0)