From 9f62939eab11173e2214b5074372d8d8413537d5 Mon Sep 17 00:00:00 2001 From: Lyu YM Date: Sun, 26 Mar 2017 21:10:18 +0800 Subject: [PATCH] Update CordovaHTTP.java Add support for multi cookies, concating them into one string --- .../synconset/CordovaHTTP/CordovaHttp.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/android/com/synconset/CordovaHTTP/CordovaHttp.java b/src/android/com/synconset/CordovaHTTP/CordovaHttp.java index 71b47097..b0861e33 100644 --- a/src/android/com/synconset/CordovaHTTP/CordovaHttp.java +++ b/src/android/com/synconset/CordovaHTTP/CordovaHttp.java @@ -119,9 +119,24 @@ protected void addResponseHeaders(HttpRequest request, JSONObject response) thro for (Map.Entry> entry : headers.entrySet()) { String key = entry.getKey(); List value = entry.getValue(); - if ((key != null) && (!value.isEmpty())) { - parsed_headers.put(key, value.get(0)); - } + if(key != null) { + if(value.size() == 1) { + parsed_headers.put(key, value.get(0)); + } + else if(value.size() > 1) { // multi cookies, usually 'Set-Cookie' header + StringBuffer sb = new StringBuffer(64); + for(String val : value) { + int index = val.indexOf("path="); // remove "path=/" at the end of a cookie + if( index >= 0) { + sb.append(val.substring(0, index)); + } + else { + sb.append(val); + } + } + parsed_headers.put(key, sb.toString()); + } + } // end of 'if(key != null)' } response.put("headers", new JSONObject(parsed_headers)); }