Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TcpSocket and XMLHttpRequest

131 views
Skip to first unread message

Roger Dentz

unread,
Aug 15, 2013, 9:20:36 AM8/15/13
to
me (Roger Dentz change)
Aug 14 (15 hours ago)
Hello,

I'm developing a B2G app that sends multipart/related data to a server. The data is an XML header (part 1) followed by a binary file wrapped in XML (part 2). The file can be large and needs to be sent using http chunking. I don't see how to do http chunking with XMLHttpRequest, and TcpSocket won't let you use port 80 for non-certified apps (app will be privileged, just not certified). Are there any other options?

Thanks!

Andrew Sutherland

unread,
Aug 15, 2013, 10:44:44 AM8/15/13
to dev-w...@lists.mozilla.org
On 08/15/2013 09:20 AM, Roger Dentz wrote:
> I'm developing a B2G app that sends multipart/related data to a server. The data is an XML header (part 1) followed by a binary file wrapped in XML (part 2). The file can be large and needs to be sent using http chunking. I don't see how to do http chunking with XMLHttpRequest, and TcpSocket won't let you use port 80 for non-certified apps (app will be privileged, just not certified). Are there any other options?

There is currently no way to produce data on demand for XHR from
content-space. (Chrome code in Firefox is capable of doing it,
however.) The good news is that XHR lets you send a Blob, and you can
build a Blob out of multiple parts, including other Blobs that are
disk-backed. See
https://developer.mozilla.org/en-US/docs/Web/API/Blob#Constructor

Presumably your data is already coming from disk, so this should work out.

For example:
var myAggregateBlob = new Blob([multipartRelatedStuffAndXML, myFileBlob,
multipartRelatedPartEnd])

Andrew

Roger Dentz

unread,
Aug 15, 2013, 11:29:43 AM8/15/13
to
However it needs to be sent chunked - http://en.wikipedia.org/wiki/Chunked_transfer_encoding
The header needs to include "transfer-encoding: chunked" and each block needs to be preceded by a length field. This is a requirement of the server, whether we have all the info available on disk or not.

-R.

Andrew Sutherland

unread,
Aug 15, 2013, 12:20:06 PM8/15/13
to dev-w...@lists.mozilla.org
On 08/15/2013 11:29 AM, Roger Dentz wrote:
> However it needs to be sent chunked - http://en.wikipedia.org/wiki/Chunked_transfer_encoding
> The header needs to include "transfer-encoding: chunked" and each block needs to be preceded by a length field. This is a requirement of the server, whether we have all the info available on disk or not.

Chunked encoding doesn't seem to require any discussion between the
server and your client, so you should be able to just pre-can all of the
chunks.

Blobs know their length (.size) and can be sliced
(https://developer.mozilla.org/en-US/docs/Web/API/Blob#slice%28%29). If
the server is fine with a single chunk, it seems like you could add that
boilerplate. If the server wants to hear about things in smaller
chunks, you can slice up the Blob to fake smaller chunks and provide the
boilerplate for those chunks too. Those slices will still only be
streamed from disk as they are needed.

Unless XHR isn't letting you set the transfer-encoding header?

Andrew

Roger Dentz

unread,
Aug 15, 2013, 4:02:11 PM8/15/13
to
Yeah, that's about the size of it. It ignores setRequestHeader for transfer-encoding=chunked and sets the content-length to whatever the sum of all your blob parts is.

-R.

Roger Dentz

unread,
Aug 15, 2013, 4:06:25 PM8/15/13
to
So I think I'll focus on TcpSocket - there were several code samples where they access port 80 so maybe that's a doc typo where it says apps have to be certified to access any port < 1024. Seems benign enough to allow port 80 access since that's what XHR does anyway. Right now it doesn't work for any port so still need to poke around a little.

Thanks fer the advice,
-R.

Jonas Sicking

unread,
Sep 21, 2013, 2:42:00 PM9/21/13
to Roger Dentz, dev-w...@lists.mozilla.org
Could you file a bug on this. I believe that for systemXHR we should
permit setting more headers.

/ Jonas
> _______________________________________________
> dev-webapps mailing list
> dev-w...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-webapps

Roger Dentz

unread,
Sep 23, 2013, 1:31:16 PM9/23/13
to
On Saturday, September 21, 2013 11:42:00 AM UTC-7, Jonas Sicking wrote:
> Could you file a bug on this. I believe that for systemXHR we should
>
> permit setting more headers.
>
>
>
> / Jonas

This has been resolved - TcpSocket worked fine. The line "Note: Only certified apps can use a port below 1024." from here - https://developer.mozilla.org/en-US/docs/Web/API/TCPSocket - should read "Note: Only certified apps can listen to a port below 1024."
0 new messages