Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: abh/restler
...
head fork: abh/restler
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 12 additions and 45 deletions.
  1. +1 −1  README.md
  2. +10 −43 lib/restler.js
  3. +1 −1  package.json
View
2  README.md
@@ -1,4 +1,4 @@
-Restler 0.2.4
+Restler
===========
(C) Dan Webb (dan@danwebb.net/@danwrong) 2011, Licensed under the MIT-LICENSE
View
53 lib/restler.js
@@ -3,8 +3,7 @@ var sys = require('util'),
https = require('https'),
url = require('url'),
qs = require('querystring'),
- multipart = require('./multipartform'),
- zlib = require('zlib');
+ multipart = require('./multipartform');
function mixin(target, source) {
Object.keys(source).forEach(function(key) {
@@ -108,46 +107,24 @@ mixin(Request.prototype, {
} else {
var body = '';
- response.setEncoding('binary');
+ response.setEncoding('utf8');
response.on('data', function(chunk) {
body += chunk;
});
response.on('end', function() {
- self._decode(new Buffer(body, 'binary'), response, function(err, body) {
- if (err) {
- self._respond('error', '', 'Failed to decode response body');
- return;
- }
- self._encode(body, response, function(body) {
- self._fireEvents(body, response);
- });
- });
+ if (self.options.parser) {
+ self.options.parser.call(response, body, function(parsedData) {
+
+ self._fireEvents(parsedData, response);
+ });
+ } else {
+ self._fireEvents(body, response);
+ }
});
}
},
- _decode: function(body, response, callback) {
- var encoder = response.headers['content-encoding'];
- if (encoder in decoders) {
- decoders[encoder].call(response, body, callback);
- } else {
- callback(null, body);
- }
- },
- _encode: function(body, response, callback) {
- var self = this;
- if (self.options.decoding == 'buffer') {
- callback(body);
- } else {
- body = body.toString(self.options.decoding);
- if (self.options.parser) {
- self.options.parser.call(response, body, callback);
- } else {
- callback(body);
- }
- }
- },
_respond: function(type, data, response) {
if (this.options.originalRequest) {
this.options.originalRequest.emit(type, data, response);
@@ -276,16 +253,6 @@ try {
parsers.auto.matchers['application/xml'] = parsers.xml;
} catch(e) { }
-var decoders = {
- gzip: function(buf, callback) {
- zlib.gunzip(buf, callback);
- },
- deflate: function(buf, callback) {
- zlib.inflate(buf, callback);
- }
-};
-
-
function Service(defaults) {
if (defaults.baseURL) {
this.baseURL = defaults.baseURL;
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "restler",
- "version": "0.2.4",
+ "version": "0.2.5",
"description": "An HTTP client library for node.js",
"contributors": [{ "name": "Dan Webb", "email": "dan@danwebb.net" }],
"homepage": "https://github.com/danwrong/restler",

No commit comments for this range

Something went wrong with that request. Please try again.