Skip to content

Commit ecb2e74

Browse files
committed
compatible with lower-case http headers
1 parent af84bbe commit ecb2e74

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/main/java/com/aliyun/oss/common/comm/DefaultServiceClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ protected static ResponseMessage buildResponse(ServiceClient.Request request, Cl
162162
}
163163

164164
for (Header header : httpResponse.getAllHeaders()) {
165-
if (HttpHeaders.CONTENT_LENGTH.equals(header.getName())) {
165+
if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(header.getName())) {
166166
response.setContentLength(Long.parseLong(header.getValue()));
167167
}
168168
response.addHeader(header.getName(), header.getValue());

src/main/java/com/aliyun/oss/common/comm/HttpMesssage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121

2222
import java.io.IOException;
2323
import java.io.InputStream;
24-
import java.util.HashMap;
2524
import java.util.Map;
25+
import java.util.TreeMap;
2626

2727
/**
2828
* Common class for both HTTP request and HTTP response.
2929
*/
3030
public abstract class HttpMesssage {
3131

32-
private Map<String, String> headers = new HashMap<String, String>();
32+
private Map<String, String> headers = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);;
3333
private InputStream content;
3434
private long contentLength;
3535

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,7 @@ public static BucketMetadata parseBucketMetadata(Map<String, String> headers) th
14781478
for (Iterator<String> it = headers.keySet().iterator(); it.hasNext();) {
14791479
String key = it.next();
14801480

1481-
if (key.equals(OSSHeaders.OSS_BUCKET_REGION)) {
1481+
if (key.equalsIgnoreCase(OSSHeaders.OSS_BUCKET_REGION)) {
14821482
bucketMetadata.setBucketRegion(headers.get(key));
14831483
} else {
14841484
bucketMetadata.addHttpMetadata(key, headers.get(key));
@@ -1503,20 +1503,20 @@ public static SimplifiedObjectMeta parseSimplifiedObjectMeta(Map<String, String>
15031503
for (Iterator<String> it = headers.keySet().iterator(); it.hasNext();) {
15041504
String key = it.next();
15051505

1506-
if (key.equals(OSSHeaders.LAST_MODIFIED)) {
1506+
if (key.equalsIgnoreCase(OSSHeaders.LAST_MODIFIED)) {
15071507
try {
15081508
objectMeta.setLastModified(DateUtil.parseRfc822Date(headers.get(key)));
15091509
} catch (ParseException pe) {
15101510
throw new ResponseParseException(pe.getMessage(), pe);
15111511
}
1512-
} else if (key.equals(OSSHeaders.CONTENT_LENGTH)) {
1512+
} else if (key.equalsIgnoreCase(OSSHeaders.CONTENT_LENGTH)) {
15131513
Long value = Long.valueOf(headers.get(key));
15141514
objectMeta.setSize(value);
1515-
} else if (key.equals(OSSHeaders.ETAG)) {
1515+
} else if (key.equalsIgnoreCase(OSSHeaders.ETAG)) {
15161516
objectMeta.setETag(trimQuotes(headers.get(key)));
1517-
} else if (key.equals(OSSHeaders.OSS_HEADER_REQUEST_ID)) {
1517+
} else if (key.equalsIgnoreCase(OSSHeaders.OSS_HEADER_REQUEST_ID)) {
15181518
objectMeta.setRequestId(headers.get(key));
1519-
} else if (key.equals(OSSHeaders.OSS_HEADER_VERSION_ID)) {
1519+
} else if (key.equalsIgnoreCase(OSSHeaders.OSS_HEADER_VERSION_ID)) {
15201520
objectMeta.setVersionId(headers.get(key));
15211521
}
15221522
}
@@ -1563,16 +1563,16 @@ public static ObjectMetadata parseObjectMetadata(Map<String, String> headers) th
15631563
if (key.indexOf(OSSHeaders.OSS_USER_METADATA_PREFIX) >= 0) {
15641564
key = key.substring(OSSHeaders.OSS_USER_METADATA_PREFIX.length());
15651565
objectMetadata.addUserMetadata(key, headers.get(OSSHeaders.OSS_USER_METADATA_PREFIX + key));
1566-
} else if (key.equals(OSSHeaders.LAST_MODIFIED) || key.equals(OSSHeaders.DATE)) {
1566+
} else if (key.equalsIgnoreCase(OSSHeaders.LAST_MODIFIED)||key.equalsIgnoreCase(OSSHeaders.DATE)) {
15671567
try {
15681568
objectMetadata.setHeader(key, DateUtil.parseRfc822Date(headers.get(key)));
15691569
} catch (ParseException pe) {
15701570
throw new ResponseParseException(pe.getMessage(), pe);
15711571
}
1572-
} else if (key.equals(OSSHeaders.CONTENT_LENGTH)) {
1572+
} else if (key.equalsIgnoreCase(OSSHeaders.CONTENT_LENGTH)) {
15731573
Long value = Long.valueOf(headers.get(key));
15741574
objectMetadata.setHeader(key, value);
1575-
} else if (key.equals(OSSHeaders.ETAG)) {
1575+
} else if (key.equalsIgnoreCase(OSSHeaders.ETAG)) {
15761576
objectMetadata.setHeader(key, trimQuotes(headers.get(key)));
15771577
} else {
15781578
objectMetadata.setHeader(key, headers.get(key));

src/main/java/com/aliyun/oss/model/ObjectMetadata.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.text.ParseException;
2424
import java.util.Collections;
2525
import java.util.Date;
26-
import java.util.HashMap;
26+
import java.util.TreeMap;
2727
import java.util.Map;
2828

2929
import com.aliyun.oss.common.utils.DateUtil;
@@ -37,10 +37,10 @@
3737
public class ObjectMetadata {
3838

3939
// The user's custom metadata, whose prefix in http header is x-oss-meta-.
40-
private Map<String, String> userMetadata = new HashMap<String, String>();
40+
private Map<String, String> userMetadata = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
4141

4242
// Other non-custom metadata.
43-
protected Map<String, Object> metadata = new HashMap<String, Object>();
43+
protected Map<String, Object> metadata = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
4444

4545
public static final String AES_256_SERVER_SIDE_ENCRYPTION = "AES256";
4646

0 commit comments

Comments
 (0)