Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

head() must not provide body #190

Closed
ghost opened this Issue Feb 25, 2012 · 3 comments

Comments

Projects
None yet
1 participant
@ghost

ghost commented Feb 25, 2012

I get a strange error message:

Error: HTTP HEAD requests MUST NOT include a request body.

The issue is that I haven't provided a body in my head request:

request.head(apiInfo['x-storage-url'] + '/' + name, {
  headers: {
    'X-Auth-Token': apiInfo['x-auth-token'],
    'Accept': 'application/json'
  }
}, function (err, res) {...});

Why do I get this error?

Owner

mikeal commented Feb 25, 2012

I'm doing this on master and not seeing this error.

r.head('http://www.google.com', {headers:{accept:'application/json'}}, function (err, resp) {console.error(resp.statusCode)})

Can you verify that there isn't a forward or something else going on?

@ghost

ghost commented Feb 26, 2012

I see what the issue is.

The code looks like this in Request:

if (params.options.body || params.options.requestBodyStream || params.options.json || params.options.multipart) {...}

I have set json to default:

var request = require('request').defaults({
  json: true
});

I tried to override it with:

request.head(apiInfo['x-storage-url'] + '/' + name, {
  json: false,
  headers: {
    'X-Auth-Token': apiInfo['x-auth-token'],
    'Accept': 'application/json'
  }
}, function (err, res) {...});

But it wasn't overridden.

Possible solutions:

  1. Make it possible to override.
  2. Automatically ignore even if JSON is set.

@mikeal mikeal closed this in 0ea2351 Feb 27, 2012

Owner

mikeal commented Feb 27, 2012

That check is from before we has support for decoding JSON bodies and the option was only for the POST body to be encoded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment