Do not use JSON as default Accept header when no produces present

This commit is contained in:
xhh 2015-05-26 10:35:49 +08:00
parent aa03be7f76
commit 951b7a9075
3 changed files with 13 additions and 5 deletions

View File

@ -108,7 +108,7 @@ public class ApiInvoker {
}
public static String selectHeaderAccept(String[] accepts) {
if (accepts.length == 0) return "application/json";
if (accepts.length == 0) return null;
if (StringUtil.containsIgnoreCase(accepts, "application/json")) return "application/json";
return StringUtil.join(accepts, ",");
}
@ -194,7 +194,11 @@ public class ApiInvoker {
}
String querystring = b.toString();
Builder builder = client.resource(host + path + querystring).accept(accept);
Builder builder;
if (accept == null)
builder = client.resource(host + path + querystring).getRequestBuilder();
else
builder = client.resource(host + path + querystring).accept(accept);
for(String key : headerParams.keySet()) {
builder = builder.header(key, headerParams.get(key));
}

View File

@ -108,7 +108,7 @@ public class ApiInvoker {
}
public static String selectHeaderAccept(String[] accepts) {
if (accepts.length == 0) return "application/json";
if (accepts.length == 0) return null;
if (StringUtil.containsIgnoreCase(accepts, "application/json")) return "application/json";
return StringUtil.join(accepts, ",");
}
@ -194,7 +194,11 @@ public class ApiInvoker {
}
String querystring = b.toString();
Builder builder = client.resource(host + path + querystring).accept(accept);
Builder builder;
if (accept == null)
builder = client.resource(host + path + querystring).getRequestBuilder();
else
builder = client.resource(host + path + querystring).accept(accept);
for(String key : headerParams.keySet()) {
builder = builder.header(key, headerParams.get(key));
}

View File

@ -19,7 +19,7 @@ public class ApiInvokerTest {
assertEquals("text/plain,application/xml", ApiInvoker.selectHeaderAccept(accepts));
accepts = new String[] { };
assertEquals("application/json", ApiInvoker.selectHeaderAccept(accepts));
assertNull(ApiInvoker.selectHeaderAccept(accepts));
}
@Test