Setting content-type header with restify results in application/octet-stream

node.js, restify

Solution

Turns out the reason this was failing is because I was not sending the response using `Restify`'s response handler; it was defaulting to the native Node.js handler.

Where I was doing this:

res.send(js2xmlparser("search", obj));

I should have been doing this:

res.end(js2xmlparser("search", o));
//  ^ end, not send!

Problem

I'm trying out restify, and though I'm more comfortable with Express, so far it's pretty awesome. I'm trying to set the content type header in the response like so: ``` server.get('/xml', function(req, res) { res.setHeader('content-type', 'application/xml'); // res.header('content-type', 'application/xml'); // tried this too // res.contentType = "application/xml"; // tried this too res.send("<root><test>stuff</test></root>"); }); ``` But the response I get back is instead `application/octet-stream`. I also tried `res.contentType('application/xml')` but that actually threw an error (`"Object HTTP/1.1 200 OK\ has no method 'contentType'"`). What is the correct way to set the content type header to xml on the response? Update: When I do `console.log(res.contentType);` it actually outputs `application/xml`. Why is it not in the response headers? Curl snippet: ``` * Hostname was NOT found in DNS cache * Trying 127.0.0.1... * Connected to localhost (127.0.0.1) port 8080 (#0) > GET /xml?params=1,2,3 HTTP/1.1 > User-Agent: curl/7.39.0 > Host: localhost:8080 > Accept: */* > < HTTP/1.1 200 OK < Content-Type: application/octet-stream < Content-Length: 8995 < Date: Mon, 23 Feb 2015 20:20:14 GMT < Connection: keep-alive < <body goes here> ```

Original source