Request: Request is not redirected due to encoded location header

Created on 2 Jan 2018  ·  3Comments  ·  Source: request/request

Summary

Hi guys, I'm having trouble with sending request to URL which precedes redirection to another one after receiving 301.

Simplest Example to Reproduce

request('http://www.tanitbar.ru/menu.aspx?cat=6', function (error, response, body) {
  console.log('error:', error);
  console.log("response", response);
});,

1) First response contains status code equals to 301 (that means that we should redirect to URL from location header, but it contains encoded Russian letters: Салаты

2) Since this URL (http://www.tanitbar.ru/Салаты) doesn't exist, I'm getting 404 error

Expected Behavior




Expect to get html body of page, with status code equals to 200

Current Behavior



I'm getting 404 for now

Possible Solution



curl works fine and redirects to another URL after receiving 301
curl "http://www.tanitbar.ru/menu.aspx?cat=6" -L, (curl doesn't redirect by default, therefore we need to pass -L option)

I guess we should decode location header somehow before redirection (By the way I could not decode it by hand)

Context



Couldn't receive content of the page from JS.

Your Environment

| software | version
| ---------------- | -------
| request |^2.83.0
| node |8.7.0
| npm |5.4.2
| Operating System | Linux, Ubuntu

Thanks in advance!

stale

Most helpful comment

@mikeal https://github.com/nodejs/node/issues/17390 may be related
By the way, that Buffer.from(location, 'binary').toString('utf8') works for me.

All 3 comments

Do we even do anything with the encoding of that header? I think we just get it right from Node.js' parser.

@mikeal https://github.com/nodejs/node/issues/17390 may be related
By the way, that Buffer.from(location, 'binary').toString('utf8') works for me.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nijikokun picture nijikokun  ·  61Comments

maiko-rocha picture maiko-rocha  ·  51Comments

danielgindi picture danielgindi  ·  20Comments

matthewgertner picture matthewgertner  ·  24Comments

sherodtaylor picture sherodtaylor  ·  18Comments