Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

head() must not provide body #190

Closed
ghost opened this Issue · 3 comments

1 participant

@ghost

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
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?

@ghost

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
@mikeal
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.