Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removeRefererHeader docs #1858

Closed
calibr opened this issue Oct 23, 2015 · 9 comments
Closed

removeRefererHeader docs #1858

calibr opened this issue Oct 23, 2015 · 9 comments

Comments

@calibr
Copy link
Contributor

calibr commented Oct 23, 2015

in documentation:

removeRefererHeader - removes the referer header when a redirect happens (default: false).

but actually it doesn't remove Referer, it just reuses its value from initial request(like browsers behave). I guess that need to do some corrections in docs about this option.

@simov
Copy link
Member

simov commented Oct 23, 2015

Can you provide a short example or a failing test? Here is the current test regarding that behavior.

@calibr
Copy link
Contributor Author

calibr commented Oct 23, 2015

ok, I'll do it soon

@simov
Copy link
Member

simov commented Oct 23, 2015

Also note that earlier today I submitted another PR attemting to fix the referer header behavior #1857

@calibr
Copy link
Contributor Author

calibr commented Oct 23, 2015

if add referer header in test you selected it fails:

tape('should not have a referer when removeRefererHeader is true', function(t) {
  request.post({
    uri: s.url + '/temp',
    jar: jar,
    followAllRedirects: true,
    removeRefererHeader: true,
    headers: { cookie: 'foo=bar', referer: 'http://example.com' }
  }, function(err, res, body) {
    t.equal(err, null)
    t.equal(res.statusCode, 200)
    t.end()
  })
  .on('redirect', function() {
    t.equal(this.headers.referer, undefined)
  })
})
# should not have a referer when removeRefererHeader is true
not ok 77 should be equal
    operator: equal
    expected: |-
      undefined
    actual: |-
      'http://example.com'

so it hasn't removed the referer header as documentation says

@simov
Copy link
Member

simov commented Oct 23, 2015

Right, now I see. As I understand it, the intention was probably to actually remove it. So instead of having:

if (!self.removeRefererHeader) {
  request.setHeader('referer', uriPrev.href)
}

It should be:

if (self.removeRefererHeader) {
  request.removeHeader('referer')
} else {
  request.setHeader('referer', uriPrev.href)
}

Of course the test should be fixed too. What do you think?

@calibr
Copy link
Contributor Author

calibr commented Oct 23, 2015

I think that current version of removeRefererHeader=true provides the way to process Referer as browsers do it, just preserve Referer from initial request, and in my opinion it's a reasonable behaviour. so I don't think that this behaviour should be changed, because some library users may occur broken if they use this option to behave in redirects like a browser. Probably it should be only a correction in the docs to describe this option more clearly.

@simov
Copy link
Member

simov commented Oct 23, 2015

Yep, I think the current implementation is good. We just need additional test for the case when you manually set the referer header in the initial request. I think I'm going to add one tomorrow.

As for the docs, I'm open for suggestions:

removeRefererHeader - removes the referer header when a redirect happens (default: false). Note: referer header set in the initial request is preserved during redirect.

@calibr
Copy link
Contributor Author

calibr commented Oct 23, 2015

👍

little suggestion:

removeRefererHeader - removes the referer header when a redirect happens (default: false). Note: if true, referer header set in the initial request is preserved during redirect chain.

(added "if true" and "chain")

@simov
Copy link
Member

simov commented Oct 24, 2015

Fixed in #1860

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants