meteor/meteor — pull request #1670 by aldeed (2013-12-08 14:14:56+00:00)
Title: Add "responseType" and "encoding" options to HTTP.call

This adds a `responseType` option to HTTP.call on both the client and the server. It also adds an `encoding` option on the server. It supersedes pull request #451, adding the same functionality but with additional features that keep things similar between client and server.

This development is backwards compatible with existing code.

The new `responseType` option on the client matches the [xhr2 spec](http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute) with the addition of one custom option: "ejson-binary". On the server, I've added custom code to match the client xhr2 options where possible.

The new `responseType` option can be one of the following string values:

* "string": `result.content` will be a `String` (this is the default and matches the current behavior)
* "blob": (Client only) `result.content` will be a `Blob`
* "document": (Client only) `result.content` will be a `Document`
* "buffer": (Server only) `result.content` will be a `Buffer` (setting `encoding` to `null` does the same thing)
* "arraybuffer": `result.content` will be an `ArrayBuffer`
* "ejson-binary": `result.content` will be an `EJSON.binary`
* "json": `result.content` will be an `Object`

On the server only, you may additionally specify the desired encoding with the `encoding` option when `responseType` is "string". This takes string values matching those from Node's `Buffer.toString` method.

Note that I coded this to be backwards compatible, but technically the responseType could be automatically set to "json" based on the content-type header of the response, and then you could deprecate the `.data` property and `populateData` function.

There are client and server tests for all response types, and all of the existing tests still pass. I can update the docs if you wish, too, but I wasn't sure if some of that was autogenerated in some way.

There was a little prior discussion about this on the [meteor core list](https://groups.google.com/forum/#!topic/meteor-core/4PTD_Lnq-_Q).