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

Fix OSS check #479

Closed
wants to merge 2 commits into from
Closed

Fix OSS check #479

wants to merge 2 commits into from

Conversation

chinesedfan
Copy link

Pull Request Template:

Describe what you did

Fix function is_oss_ok.

  • the recursive call should use the whole rest part as an argument
  • the awk picks the wrong location with \r at the end

How you did it

Fixed by,

  • wrap the rest by backticks
  • replace awk with sed

How to verify it doesn't effect the functionality of n

NODE_MIRROR=https://npm.taobao.org/mirrors/node/ n 8.9.0

If this solves an issue, please put issue in PR notes.

If this solves an issue, please include the output of issue that had problems and then the fixed output from the same command.

  • Before
[zhong@localhost n]$ NODE_MIRROR=https://npm.taobao.org/mirrors/node/ n 8.9.0

     install : node-v8.9.0

  Error: invalid version 8.9.0
  • After (Very quickly in China! But the official nodejs.org is slow due to network censorship.)
[zhong@localhost n]$ NODE_MIRROR=https://npm.taobao.org/mirrors/node/ n 8.9.0

     install : node-v8.9.0
       mkdir : /usr/local/n/versions/node/8.9.0
       fetch : https://npm.taobao.org/mirrors/node/v8.9.0/node-v8.9.0-darwin-x64.tar.gz
######################################################################## 100.0%
   installed : v8.9.0

Squash any unnecessary commits to keep history clean as possible

Only 1 commit.

Place description for the changelog in PR so we can tally all changes for any future release

Fix OSS check then able to download from special mirror sites.

@chinesedfan
Copy link
Author

Updated with an optimization that saving headers in a local variable. Now it only needs to send 2 requests to check OSS resources, while the old implementation needs 4 requests.

@shadowspawn
Copy link
Collaborator

I agree is_oss_ok was broken, but I am unable to reproduce the failure as described. Is n still failing for you in the same way?

I tried reproducing with MacOS and centos:6.6 and ubuntu:12.04 and ubuntu:latest.

For your interest, I am trying a different approach by changing is_ok, no parsing, no extra requests:

function is_ok() {
  if command -v curl &> /dev/null; then
    ${GET} --fail --head "$1" &> /dev/null || return 1
  else
    ${GET} --spider "$1" &> /dev/null || return 1
  fi
}

@chinesedfan
Copy link
Author

@JohnRGee It was several months ago. Maybe something has changed. grep Location will include \r\n and cause the re-fetch throws an error.

Thanks for your is_ok. But can you explain a little more about why it can handle 302 as well?

@shadowspawn
Copy link
Collaborator

shadowspawn commented Jul 21, 2018

Redirects:

  • CURL_PARAMS includes -L so curl follows redirects
  • wget follows up to 20 redirects by default according to this page, see --max-redirect

I checked archlinux and centos and ubuntu and Mac.

Example:

# wget -O- --spider https://npm.taobao.org/mirrors/node/v9.11.0/node-v9.11.0-linux-arm64.tar.gz
...
HTTP request sent, awaiting response... 302 Found
Location: http://cdn.npm.taobao.org/dist/node/v9.11.0/node-v9.11.0-linux-arm64.tar.gz [following]
Spider mode enabled. Check if remote file exists.
--2018-07-21 12:07:49--  http://cdn.npm.taobao.org/dist/node/v9.11.0/node-v9.11.0-linux-arm64.tar.gz
...
HTTP request sent, awaiting response... 200 OK
Length: 17897624 (17M) [application/octet-stream]
Remote file exists.

# curl --head -L https://npm.taobao.org/mirrors/node/v9.11.0/node-v9.11.0-linux-arm64.tar.gz
HTTP/2 302 
...

HTTP/1.1 200 OK
...
Content-Length: 17897624
....

Copy link
Collaborator

@shadowspawn shadowspawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I am not a maintainer.)

When I tried working through the code I found it does not currently work as intended. The location returned is currently all lowercase.

$ curl -Is -L https://npm.taobao.org/mirrors/node/v10.0.0/node-v10.0.0-darwin-x64.tar.gz | grep ocation
location: http://cdn.npm.taobao.org/dist/node/v10.0.0/node-v10.0.0-darwin-x64.tar.gz

I checked and headers are officially case insensitive, so I suggest the searches are case insensitive too.

https://tools.ietf.org/html/rfc7230#section-3.2

@shadowspawn
Copy link
Collaborator

See #560 for open issue. Subscribe to that for updates and/or add 👍 to show interest

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

Successfully merging this pull request may close these issues.

2 participants