Skip to content

Instantly share code, notes, and snippets.

@PaulMougel
Last active August 29, 2015 14:06
Show Gist options
  • Save PaulMougel/b962949958e26e932b8a to your computer and use it in GitHub Desktop.
Save PaulMougel/b962949958e26e932b8a to your computer and use it in GitHub Desktop.
hapi gzip issue

Image 280, served from filesystem

MD5 (/image/280 from Chrome)              = 00f543dd8a14fa23f6b43806a97cd415
MD5 (/image/280.nii.gz from Chrome)       = 00f543dd8a14fa23f6b43806a97cd415
MD5 (/image/280 from curl)                = 00f543dd8a14fa23f6b43806a97cd415
MD5 (/image/280.nii.gz from curl)         = 00f543dd8a14fa23f6b43806a97cd415
MD5 (/image/280 from Firefox)             = 00f543dd8a14fa23f6b43806a97cd415
MD5 (/image/280.nii.gz from Firefox)      = 66e40034de146a20ce146df0eccb184b
MD5 (image stored on filesystem)          = 00f543dd8a14fa23f6b43806a97cd415

If we run gunzip -c FILE | md5 on the file that has the wrong md5 sum, we get the correct hash. This means that for some reason, Firefox downloads a double-compressed file on the /image/280.nii.gz URL.

Relevant hapi code:

request.headers['accept-encoding'] = undefined;
reply.file(path, {filename: name, mode: 'attachment'});
GET /image/280
Chrome request headers:
  Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  Accept-Encoding:gzip,deflate,sdch
Response headers:
  content-disposition:attachment; filename=ssubject010_MPRAGE
  content-encoding:gzip
  content-type:application/octet-stream
  Transfer-Encoding:chunked
  vary:accept-encoding

GET /image/280
curl request headers:
  Accept: */*
Response headers:
  content-type: application/octet-stream
  content-disposition: attachment; filename=ssubject010_MPRAGE

GET /image/280
Firefox request headers:
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Encoding: gzip, deflate
Response headers:
  Content-Disposition: attachment; filename=ssubject010_MPRAGE
  Content-Encoding: gzip
  Content-Type: application/octet-stream
  Transfert-Encoding: chunked
  Vary: accept-encoding

GET /image/280.nii.gz
Chrome request headers:
  Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  Accept-Encoding:gzip,deflate,sdch
Response headers:
  content-disposition:attachment; filename=ssubject010_MPRAGE
  content-encoding:gzip
  content-type:application/octet-stream
  Transfer-Encoding:chunked
  vary:accept-encoding

GET /image/280.nii.gz
curl request headers:
  Accept: */*
Response headers:
  content-type: application/octet-stream
  content-disposition: attachment; filename=ssubject010_MPRAGE

GET /image/280.nii.gz
Firefox request headers:
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Encoding: gzip, deflate
Response headers:
  Content-Disposition: attachment; filename=ssubject010_MPRAGE
  Content-Encoding: gzip
  Content-Type: application/octet-stream
  Transfert-Encoding: chunked
  Vary: accept-encoding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment