Skip to content
This repository

head() must not provide body #190

Closed
ghost opened this Issue · 3 comments

1 participant

Mikeal Rogers
Deleted user

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?

Mikeal Rogers
Owner

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?

Deleted user

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 Rogers
Owner

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
Something went wrong with that request. Please try again.