eBay / jsonpipe

A lightweight AJAX client for chunked JSON responses

Home Page:http://ebay.github.io/jsonpipe/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Asynchronous loading doesn't work in Safari

m-koester opened this issue · comments

Hi Senthil,

When I use jsonpipe on Mac OS X (Version 8.0.7 (10600.7.12)), the success callback is only called when the whole response was received. The problem is that in Safari the 'Transfer-Encoding' header is set to 'Identity' and this prevents jsonpipe to recognize the response as chunked. I already developed a patch and will try to attach it to this issue. And I really like your project!

Cheers,
Matthias

Here is my patch which fixes the problem in Safari:

From 05e1699c91b8659b064fc9ee7208331a57112ea1 Mon Sep 17 00:00:00 2001
From: "m.koester" <m.koester m.koester@binaere-bauten.de>
Date: Fri, 11 Sep 2015 10:28:03 +0200
Subject: [PATCH] Fixed transfer encoding detection in Safari

---
 jsonpipe.js | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/jsonpipe.js b/jsonpipe.js
index 969820d..1edc5dd 100644
--- a/jsonpipe.js
+++ b/jsonpipe.js
@@ -131,7 +131,9 @@ function send(url, options) {
             chromeSpdy;
         if (xhr.readyState === state.HEADERS_RECEIVED) {
             encoding = xhr.getResponseHeader('Transfer-Encoding') || '';
-            isChunked = encoding.toLowerCase().indexOf('chunked') > -1;
+            encoding = encoding.toLowerCase();
+            isChunked = encoding.indexOf('chunked') > -1
+                || encoding.indexOf('identity') > -1; // fix for Safari
             if (!isChunked) {
                 // SPDY inherently uses chunked transfer and does not define a header.
                 // Firefox provides a synthetic header which can be used instead.
@@ -195,4 +197,4 @@ module.exports = {
 };
 },{}]},{},[1])
 (1)
-});
\ No newline at end of file
+});
-- 
2.3.2 (Apple Git-55)

Thanks @m-koester Added the fix and published a new version