Skip to content

Instantly share code, notes, and snippets.

@achingbrain
Last active August 29, 2015 14:23
Show Gist options
  • Save achingbrain/c257e68c4ff547d09328 to your computer and use it in GitHub Desktop.
Save achingbrain/c257e68c4ff547d09328 to your computer and use it in GitHub Desktop.
Trying to download a tarball from Nexus with npm

npm pack outputs a .tgz file which we've deployed to Nexus:

$ curl -I http://nexus/path/foo.tgz
HTTP/1.1 200 OK
Date: Mon, 29 Jun 2015 08:40:25 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: JSESSIONID=10ob3uo99m54y;Path=/nexus
Content-Type: application/x-compressed
Last-Modified: Fri, 26 Jun 2015 10:16:45 GMT
ETag: "ddc61f4aad304e6ba979df170ed4b803c1507500"
Date: Mon, 29 Jun 2015 08:40:25 GMT
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Server: Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V4
Content-Length: 9765

Content-Type: application/x-compressed? Ok. npm requests everything with the accept header application/x-tar, application/vnd.github+json; q=0.1:

$ curl -I http://nexus/path/foo.tgz -H 'accept: application/x-tar, application/vnd.github+json; q=0.1'
HTTP/1.1 406 The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request
Date: Mon, 29 Jun 2015 08:42:38 GMT
Set-Cookie: JSESSIONID=11l8sft97ludk;Path=/nexus
Date: Mon, 29 Jun 2015 08:42:38 GMT
Server: Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V4
Content-Length: 0

406 due to the accept header? Ok, let's bend like a reed in the wind and just deploy it as a tar:

$ curl -I http://nexus/path/foo.tar
HTTP/1.1 200 OK
Date: Mon, 29 Jun 2015 08:44:17 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: JSESSIONID=10wiftc0c3pci;Path=/nexus
Content-Type: application/x-tar
Last-Modified: Mon, 29 Jun 2015 08:26:13 GMT
ETag: "6575d2d4a75b455ed6602983a378fc097ab3eeb7"
Date: Mon, 29 Jun 2015 08:44:17 GMT
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Server: Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V4
Content-Length: 9764

Content-Type: application/x-tar, so far, so good. Now request it how npm would do it:

$ curl -I http://nexus/path/foo.tar -H 'accept: application/x-tar, application/vnd.github+json; q=0.1'
HTTP/1.1 406 The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request
Date: Mon, 29 Jun 2015 08:45:09 GMT
Set-Cookie: JSESSIONID=2owpio74l9e4;Path=/nexus
Date: Mon, 29 Jun 2015 08:45:09 GMT
Server: Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V4
Content-Length: 0

406 again? Maybe it's being upset by the weird vnd.github+JSON bit?

$ curl -I http://nexus/path/foo.tar -H 'accept: application/x-tar'
HTTP/1.1 406 The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request
Date: Mon, 29 Jun 2015 08:45:58 GMT
Set-Cookie: JSESSIONID=10pqs9n9yrnaj;Path=/nexus
Date: Mon, 29 Jun 2015 08:45:58 GMT
Server: Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V4
Content-Length: 0

Nope, how very fussy. Let's try something that should not possibly work seeing as how Nexus is so sensitive to the accept header:

$ curl -I http://nexus/path/foo.tar -H 'accept: application/json'
HTTP/1.1 200 OK
Date: Mon, 29 Jun 2015 08:46:48 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: JSESSIONID=1v4i0fl7kcozj;Path=/nexus
Content-Type: application/x-tar
Last-Modified: Mon, 29 Jun 2015 08:26:13 GMT
ETag: "6575d2d4a75b455ed6602983a378fc097ab3eeb7"
Date: Mon, 29 Jun 2015 08:46:48 GMT
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Server: Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V4
Content-Length: 9764

Ahahaaahahahhhaaahahahaaa.

So Nexus refuses to serve something with the content-type application/x-tar if we specify that we accept application/x-tar but will happily serve it if we say we accept application/json. Nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment