Cannot use _changes feed (EventSource) because of incorrect MIME type returned

836 views
Skip to first unread message

Juan Hernandez

unread,
Nov 4, 2014, 6:38:19 AM11/4/14
to mobile-c...@googlegroups.com
Hi,

I'm trying to use the /db/_changes feed in a phonegap application in iOS.
I have specified the parameter feed=eventsource to use server-side events but it seems Couchbase is returning the wrong MIME type and Safari Mobile aborts the connection.

This is a snippet of the code:

var eventSource = new EventSource("http://lite.couchbase./mydb/_changes?feed=eventsource&include_docs=true");
eventSource
.onopen = function (e) {
 console
.log("EventSource opened", e);
};
eventSource
.onerror = function (e) {
 console
.log("EventSource failed", e);
};
eventSource
.onmessage = function (e) {
 console
.log("EventSource message", e.data);
};


As soon as it executes, Safari logs the error below in the console, the onerror handler gets called and the EventSource closed.

[Error] EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection. (index.html, line 0)

Is it possible to change the MIME type returned on the internal (http://lite.couchbase.) server?
Has anybody have any luck using EventSource feed?

I'll raise a bug in the issue tracker but was just checking the forum first.

Thanks
Juan

Jens Alfke

unread,
Nov 4, 2014, 12:42:04 PM11/4/14
to mobile-c...@googlegroups.com

On Nov 4, 2014, at 3:38 AM, Juan Hernandez <juanherna...@gmail.com> wrote:

I have specified the parameter feed=eventsource to use server-side events but it seems Couchbase is returning the wrong MIME type and Safari Mobile aborts the connection.

That's because Couchbase Lite doesn't support eventsource :( so it's ignoring the parameter and just returning the default feed.

Looks like eventsource is listed as a supported mode in our REST API docs. Sorry about that — those docs are adapted from CouchDB docs [which Couchbase wrote years ago] and there are some places where we didn't edit out options that CBL doesn't support. I'll get that fixed.

Also, we should add support for feed=eventsource since it would be useful for PhoneGap apps. I'll file an issue.

—Jens

Juan Hernandez

unread,
Nov 4, 2014, 5:02:32 PM11/4/14
to mobile-c...@googlegroups.com
Thanks Jens for the information.
I think it'd be great if eventsource gets supported :)

* After my first post I saw in the wiki that websockets is supported:

I tried to use it but getting some network errors when connecting.

var socket = new WebSocket("ws://lite.couchbase./mydb/_changes?feed=websocket&include_docs=true");

WebSocket network error: The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 2.)

Well, the error is always the same no matter the URL.
I presume I'm doing something wrong or is not supported but then why is it documented in the wiki? I want to believe is supported! :)

Jens Alfke

unread,
Nov 4, 2014, 5:08:10 PM11/4/14
to mobile-c...@googlegroups.com

On Nov 4, 2014, at 2:02 PM, Juan Hernandez <juanherna...@gmail.com> wrote:

* After my first post I saw in the wiki that websockets is supported:

Again, you've found something that's not supported. As the wiki says, "Couchbase Lite supports a WebSocket connection to the server's _changes feed" … but it doesn't provide a WebSocket _changes feed itself. That is, it acts as a WebSocket client but not a server yet.

—Jens

Juan Hernandez

unread,
Nov 4, 2014, 5:15:10 PM11/4/14
to mobile-c...@googlegroups.com
Oops, my eyes probably wanted to read something else.

Thanks Jens

Raihan Masud

unread,
Mar 7, 2016, 9:09:07 PM3/7/16
to Couchbase Mobile
Is this supported for Android? I see the issue is fixed for iOS. I am using CBL phonegap 1.2 and seeing the same issue. 

--Raihan
Portland, OR
Reply all
Reply to author
Forward
0 new messages