Skip to content

Commit

Permalink
only multipart tests to fix now
Browse files Browse the repository at this point in the history
  • Loading branch information
danwrong committed Feb 2, 2011
1 parent 5b0b672 commit 5199d86
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
13 changes: 8 additions & 5 deletions lib/restler.js
Expand Up @@ -42,9 +42,10 @@ function Request(uri, options) {
this.options.data = qs.stringify(this.options.data);
this.headers['Content-Type'] = 'application/x-www-form-urlencoded';
this.headers['Content-Length'] = this.options.data.length;
} else if (this.options.multipart) {
}

if (this.options.multipart) {
this.headers['Content-Type'] = 'multipart/form-data; boundary=' + multipart.defaultBoundary;
this.headers['Transfer-Encoding'] = 'chunked';
}

var proto = (this.url.protocol == 'https:') ? https : http;
Expand Down Expand Up @@ -110,6 +111,7 @@ mixin(Request.prototype, {
response.addListener('end', function() {
if (self.options.parser) {
self.options.parser.call(response, body, function(parsedData) {

self._fireEvents(parsedData, response);
});
} else {
Expand Down Expand Up @@ -192,8 +194,9 @@ var parsers = {

if (contentType) {
for (var matcher in parsers.auto.matchers) {

if (contentType == matcher) {
parsers.auto.matchers[matcher].call(this, data, callback);
return parsers.auto.matchers[matcher].call(this, data, callback);
}
}
}
Expand All @@ -216,7 +219,7 @@ try {
return callback(data && yaml.eval(data));
};

parsers.auto.parsers['application/yaml'] = parsers.yaml;
parsers.auto.matchers['application/yaml'] = parsers.yaml;
} catch(e) {}

try {
Expand All @@ -236,7 +239,7 @@ try {
}
};

parsers.auto.parsers['application/xml'] = parsers.yaml;
parsers.auto.matchers['application/xml'] = parsers.xml;
} catch(e) {}


Expand Down
28 changes: 14 additions & 14 deletions test/restler.js
Expand Up @@ -123,20 +123,20 @@ helper.testCase("Deserialization Tests", helper.dataServer, {
test.equal(true, data.ok, "returned " + sys.inspect(data));
});
},
// testAutoSerializerShouldParseXML: function(host, test) {
// rest.get(host, {
// headers: { 'Accepts': 'application/xml' }
// }).on('complete', function(data) {
// test.equal("true", data.document.ok, "returned " + sys.inspect(data));
// });
// },
// testAutoSerializerShouldParseYAML: function(host, test) {
// rest.get(host, {
// headers: { 'Accepts': 'application/yaml' }
// }).on('complete', function(data) {
// test.equal(true, data.ok, "returned " + sys.inspect(data));
// });
// }
testAutoSerializerShouldParseXML: function(host, test) {
rest.get(host, {
headers: { 'Accepts': 'application/xml' }
}).on('complete', function(data) {
test.equal("true", data.ok, "returned " + sys.inspect(data));
});
},
testAutoSerializerShouldParseYAML: function(host, test) {
rest.get(host, {
headers: { 'Accepts': 'application/yaml' }
}).on('complete', function(data) {
test.equal(true, data.ok, "returned " + sys.inspect(data));
});
}
});

helper.testCase('Redirect Tests', helper.redirectServer, {
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.js
Expand Up @@ -39,7 +39,7 @@ exports.dataServer = function() {
var yaml = "ok: true";

var server = http.createServer(function(request, response) {
response.writeHead(200, { 'Content-Type': request.headers['accepts'] });
response.writeHead(200, { 'Content-Type': request.headers['accepts'], 'test': 'thing' });

if (request.headers['accepts'] == 'application/json') {
response.write(json);
Expand Down

0 comments on commit 5199d86

Please sign in to comment.