Skip to content

Commit e8c489a

Browse files
author
hideki
committed
Previous commit is not enough to fix couchbase-life-android issue 249, this is supplemental commit.
- Http header parameter name could be all lower-cased. - content-type value could be longer than accept value (Ex 'application/json; charset=UTF-8' and `application/json`)
1 parent 852e8e5 commit e8c489a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/main/java/com/couchbase/lite/router/Router.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,13 @@ private static String getContentType(URLConnection connection) {
348348
contentType = connection.getRequestProperty("content-type");
349349
return contentType;
350350
}
351+
private static String getAccept(URLConnection connection) {
352+
String accept = connection.getRequestProperty("Accept");
353+
if (accept == null)
354+
// From Android: http://developer.android.com/reference/java/net/URLConnection.html
355+
accept = connection.getRequestProperty("accept");
356+
return accept;
357+
}
351358

352359
public void start() {
353360
// Refer to: http://wiki.apache.org/couchdb/Complete_HTTP_API_Reference
@@ -666,10 +673,10 @@ private Status sendResponseHeaders(Status status) {
666673
connection.getResHeader().add("Server", String.format("Couchbase Lite %s", getVersionString()));
667674

668675
// Check for a mismatch between the Accept request header and the response type:
669-
String accept = connection.getRequestProperty("Accept");
676+
String accept = getAccept(connection);
670677
if (accept != null && !"*/*".equals(accept)) {
671678
String responseType = connection.getBaseContentType();
672-
if (responseType != null && accept.indexOf(responseType) < 0) {
679+
if (responseType != null && responseType.indexOf(accept) < 0) {
673680
Log.e(Log.TAG_ROUTER, "Error 406: Can't satisfy request Accept: %s", accept);
674681
status = new Status(Status.NOT_ACCEPTABLE);
675682
}

0 commit comments

Comments
 (0)