question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Header name must be a valid HTTP Token (colon in header)

See original GitHub issue

Summary

I got the error [TypeError: Header name must be a valid HTTP Token [":authority"]]

Simplest Example to Reproduce


var request = require('request');

var options = {
    url: '----',
    headers: {
        ':authority': 'www.site.com',
        ':method': 'GET',
        ':scheme': 'https',
        'referer': 'https://site.com',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36'
    }
};

function callback(error, response, body) {
    if (!error && response.statusCode === 200) {
        console.log(body);
    }
    if (error) {
        console.log(error);
    }
}

request(options, callback);

Expected Behavior

I want to execute request with “:authority” header

Current Behavior

It doesn’t work.

Possible Solution

Add a flag use raw headers and pass headers as is.

Context

Plain nodejs.

Your Environment

software version
request 2.81.0
node v5.10.1
npm 5.3.0
Operating System mac os 10.12.6

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:22
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
tommedemacommented, Oct 6, 2017

@Freyert I don’t agree that this is a solution because it is not guaranteed that this API is under our control. At least this should be configurable. Many of us will want to be able to request APIs that do not adhere perfectly to IETF standards.

5reactions
Freyertcommented, Oct 6, 2017

Your API has to be fixed:

3.2.  Header Fields

   Each header field consists of a case-insensitive field name followed
   by a colon (":"), optional leading whitespace, the field value, and
   optional trailing whitespace.

https://tools.ietf.org/html/rfc7230#page-22

Read more comments on GitHub >

github_iconTop Results From Across the Web

Header name must be a valid HTTP token ["Authorization "] in ...
There should be an empty line break between the header (content-type: application/json) and the request payload/data.
Read more >
Header name must be a valid HTTP token - Postman community
Colon is an invalid character for the HTTP header as per HTTP standards given in RFC822. There is a discussion on stack overflow...
Read more >
Header name must be a valid HTTP token ["{"] #430 - GitHub
I had a previous simple test file that was working I tried to add a couple of requests in the same file but...
Read more >
postman header name must be a valid http token
postman header name must be a valid http token. You have to fetch the CSRF Token by making a GET Request: Header: "XSRF-TOKEN"...
Read more >
Error: Header name must be a valid HTTP token : r/flask - Reddit
I am new to Flask but when I am using PostMan to call a Python service running on Win10, this is the error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found