Skip to content

Commit 48eb909

Browse files
author
jeffreykzli
committed
throw 412 & 304 directly
1 parent f43d335 commit 48eb909

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/main/java/com/qcloud/cos/COSClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ public COSObject getObject(GetObjectRequest getObjectRequest)
11831183
* to wrap their code in try/catch blocks and check for this status code if they want to
11841184
* use constraints.
11851185
*/
1186-
if (cse.getStatusCode() == 412 || cse.getStatusCode() == 304) {
1186+
if ((cse.getStatusCode() == 412 && !clientConfig.isThrow412Directly()) || (cse.getStatusCode() == 304 && !clientConfig.isThrow304Directly())) {
11871187
return null;
11881188
}
11891189
throw cse;

src/main/java/com/qcloud/cos/ClientConfig.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ public class ClientConfig {
141141

142142
private boolean addLogDebugHeader = true;
143143

144+
private boolean throw412Directly = false;
145+
146+
private boolean throw304Directly = false;
147+
144148
// 不传入region 用于后续调用List Buckets(获取所有的bucket信息)
145149
public ClientConfig() {
146150
super();
@@ -517,4 +521,20 @@ public boolean isAddLogDebugHeader() {
517521
public void setAddLogDebugHeader(boolean addLogDebugHeader) {
518522
this.addLogDebugHeader = addLogDebugHeader;
519523
}
524+
525+
public boolean isThrow412Directly() {
526+
return throw412Directly;
527+
}
528+
529+
public void setThrow412Directly(boolean throw412Directly) {
530+
this.throw412Directly = throw412Directly;
531+
}
532+
533+
public boolean isThrow304Directly() {
534+
return throw304Directly;
535+
}
536+
537+
public void setThrow304Directly(boolean throw304Directly) {
538+
this.throw304Directly = throw304Directly;
539+
}
520540
}

src/main/java/com/qcloud/cos/http/DefaultCosHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ private <Y extends CosServiceRequest> void changeEndpointForRetry(CosHttpRequest
832832
for (Header header : httpResponse.getAllHeaders()) {
833833
if (Objects.equals(header.getName(), Headers.REQUEST_ID)) {
834834
String value = CodecUtils.convertFromIso88591ToUtf8(header.getValue());
835-
if (!value.isEmpty()) {
835+
if (value != null && !value.isEmpty()) {
836836
return;
837837
}
838838
}

0 commit comments

Comments
 (0)