3 ms·
I never noticed before, but it seems you can't send compressed data from an HTTP client back up to the server. Not true. It is perfectly valid for an HTTP cli
by cperciva 18y ago
I never noticed before, but it seems you can't send compressed data from an HTTP client back up to the server.
Not true. It is perfectly valid for an HTTP client to send an entity (as part of a PUT or POST, for example) with Content-Encoding: gzip. RFC 2616 specifically mentions this case, in fact.
That said, in most situations this isn't worth the effort. Until you've established a connection to an HTTP server, you have no way of knowing if it will accept any particular Content-Encoding; a server which doesn't understand the encoding of a provided entity SHOULD return a "415 Unsupported Media Type" response code, but trusting that every server you'll ever encounter will respond correctly is probably overly optimistic.
Of course, there's always the ultimate in portability: Send your data with a Content-Type of "application/octet-stream", and decompress at the back-end.
- wmf 18y agoOf course in an AJAX app you know exactly what the server supports.
- aristus 18y agoYou're on to something here, but I've never been able to get a browser to send a form POST with a custom Content-Type. Maybe something AJAXy gives you more control over the headers.
- briansmith 18y agoNo, browsers won't do it. But, you can do it in Java and I think Flash 10 lets you do it too.
- bprater 18y agoSo the big question is: can you compress this data using Javascript? Has anyone seen a packing function?
- aristus 18y agolzw-compressing the data then base-64 to armor it might give you 1.5:1 on stuff over 1KB or so. I ran into trouble with Javascript getting clever about bytes and Unicode characters. But, yeah, some efficient compressor and then an efficient url-safe encoding might do it.