Skip to content

Commit ba46c83

Browse files
committed
crc check
1 parent 6549a0f commit ba46c83

File tree

4 files changed

+98
-5
lines changed

4 files changed

+98
-5
lines changed

src/main/java/com/aliyun/oss/ClientConfiguration.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public class ClientConfiguration {
8888

8989
private Map<String, String> defaultHeaders = new LinkedHashMap<String, String>();
9090

91+
private boolean crcCheckEnabled = true;
92+
9193
/**
9294
* 构造用户代理。
9395
* @return 用户代理。
@@ -521,4 +523,20 @@ public void addDefaultHeader(String key, String value) {
521523
this.defaultHeaders.put(key, value);
522524
}
523525

526+
/**
527+
* 获取是否启动CRC校验,启动后上传下载请求数据会启动CRC校验。默认启用。
528+
* @return true 开启, false 关闭
529+
*/
530+
public boolean isCrcCheckEnabled() {
531+
return crcCheckEnabled;
532+
}
533+
534+
/**
535+
* 设置是否启动CRC校验,启动后上传下载请求数据会启动CRC校验。默认启用。
536+
* @param crcCheckEnabled
537+
*/
538+
public void setCrcCheckEnabled(boolean crcCheckEnabled) {
539+
this.crcCheckEnabled = crcCheckEnabled;
540+
}
541+
524542
}

src/main/java/com/aliyun/oss/internal/OSSOperation.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,23 @@ protected <T> T doOperation(RequestMessage request, ResponseParser<T> parser, St
128128
request.addHeader(OSSHeaders.OSS_SECURITY_TOKEN, context.getCredentials().getSecurityToken());
129129
}
130130

131-
132131
context.addRequestHandler(new RequestProgressHanlder());
133132
if (requestHandlers != null) {
134133
for (RequestHandler handler : requestHandlers)
135134
context.addRequestHandler(handler);
136135
}
137-
context.addRequestHandler(new RequestChecksumHanlder());
136+
if (client.getClientConfiguration().isCrcCheckEnabled()) {
137+
context.addRequestHandler(new RequestChecksumHanlder());
138+
}
138139

139140
context.addResponseHandler(new ResponseProgressHandler(originalRequest));
140141
if (reponseHandlers != null) {
141142
for (ResponseHandler handler : reponseHandlers)
142143
context.addResponseHandler(handler);
143144
}
144-
context.addResponseHandler(new ResponseChecksumHandler());
145+
if (client.getClientConfiguration().isCrcCheckEnabled()) {
146+
context.addResponseHandler(new ResponseChecksumHandler());
147+
}
145148

146149
ResponseMessage response = send(request, context, keepResponseOpen);
147150

src/test/java/com/aliyun/oss/integrationtests/CRCChecksumTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import junit.framework.Assert;
3131

32-
import org.junit.Ignore;
3332
import org.junit.Test;
3433

3534
import com.aliyun.oss.common.utils.IOUtils;
@@ -47,7 +46,7 @@
4746
import com.aliyun.oss.model.UploadPartRequest;
4847
import com.aliyun.oss.model.UploadPartResult;
4948

50-
@Ignore
49+
5150
public class CRCChecksumTest extends TestBase {
5251

5352
@Test
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package com.aliyun.oss.integrationtests;
21+
22+
import java.io.ByteArrayInputStream;
23+
import java.io.InputStream;
24+
25+
import junit.framework.Assert;
26+
27+
import org.junit.Test;
28+
29+
import com.aliyun.oss.ClientConfiguration;
30+
import com.aliyun.oss.OSSClient;
31+
import com.aliyun.oss.model.BucketInfo;
32+
import com.aliyun.oss.model.OSSObject;
33+
import com.aliyun.oss.model.ObjectMetadata;
34+
35+
public class ProxyTest extends TestBase {
36+
37+
@Test
38+
public void testProxy() {
39+
String key = "test/test.txt";
40+
String content = "Hello OSS.";
41+
42+
try {
43+
ClientConfiguration conf = new ClientConfiguration();
44+
conf.setProxyHost(TestConfig.PROXY_HOST);
45+
conf.setProxyPort(TestConfig.PROXY_PORT);
46+
conf.setProxyUsername(TestConfig.PROXY_USER);
47+
conf.setProxyPassword(TestConfig.PROXY_PASSWORD);
48+
49+
OSSClient ossClient = new OSSClient(
50+
TestConfig.OSS_TEST_ENDPOINT,
51+
TestConfig.OSS_TEST_ACCESS_KEY_ID,
52+
TestConfig.OSS_TEST_ACCESS_KEY_SECRET,
53+
conf);
54+
55+
BucketInfo info = ossClient.getBucketInfo(bucketName);
56+
Assert.assertEquals(info.getBucket().getName(), bucketName);
57+
58+
ObjectMetadata metadata = new ObjectMetadata();
59+
metadata.setContentLength(content.getBytes().length);
60+
ossClient.putObject(bucketName, key, new ByteArrayInputStream(content.getBytes()), metadata);
61+
62+
OSSObject ossObject = ossClient.getObject(bucketName, key);
63+
InputStream inputStream = ossObject.getObjectContent();
64+
inputStream.close();
65+
66+
ossClient.deleteObject(bucketName, key);
67+
68+
} catch (Exception e) {
69+
Assert.fail(e.getMessage());
70+
}
71+
}
72+
73+
}

0 commit comments

Comments
 (0)