Accept-Encoding: gzip: content is gzip-compressed twice - iis-7.5

I'm using IIS to serve a static file. I've configured IIS (using the GUI) to enable both static and dynamic compression.
I'm using HttpClient to download it, as follows:
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
var response = client.SendAsync(request).Result;
var stream = new FileStream("foo", FileMode.Create);
response.Content.CopyToAsync(stream)
.ContinueWith(t => stream.Close())
.Wait();
I'm inspecting the traffic using Fiddler, and I can see that the first one or two responses are not compressed. I assume that IIS is compressing the file in the background and caching it somewhere. The file written to disk is about 14MB (expected).
Later requests are compressed. I can see a Content-Encoding: gzip header in the response, and the file that is downloaded is about 360KB. It's a gzip file, as identified by Cygwin's file command.
However, when I use gzip -d to decompress it, I end up with a 660KB file which is, itself a gzip-compressed file, also identified by file.
If I decompress that file, I get back the 14MB file that I was expecting.
So: why is my file being compressed twice?

Related

how do I sniff file mime type nodejs

i am creating a api service using nodejs and express and to parse multipart request i am using multerjs. I have to receive a pdf file from rest request and it is coming as multipart/form-data and to verify file type i am checking the file.minetype
Now the issue is if someone changes the file extension like from mp4 -> pdf it also changes the mimetype to pdf and the file is accepted as pdf so how do i sniff the mimetype for content is their any way to do without any new packages. I really need to do it without using any packages as it'll take a really long to get a new package to approved

How to reupload image uploaded to server - Servant Haskell?

I have an endpoint that allows users to upload an image to the server. I used Servant.Multipart MultipartFormData Tmp to achieve this. I need to reupload this to another service - something like s3 (currently using tmp.ninja for testing). I used multipart request in Req to do so and it works well. The problem I am facing is that in Servant.Multipart the uploaded image is stored in tmp folder with a .buf extension. So when I upload it to the storage API, it is not saved as image.
createRequest content = do
multiPartBody <- reqBodyMultipart [partFileSource "files[]" content]
res <- req Network.HTTP.Req.POST (https "tmp.ninja" /: "upload.php") ( multiPartBody) jsonResponse mempty
return (responseBody res:: UploadResponse)
and this is how I run it:
runReq defaultHttpConfig $createRequest (fdPayload file)
where file is from the multipart request.
Is there a way to accomplish this without writing the file again as a png or jpeg

Difference between Transferred and Size columns in Mozilla Firexfox Network tab

I am trying to determine what the difference is between the Transferred column and Size column. Does it have to do with the difference between compressed files and uncompressed?
I am not compressing my files on my server (Node.js Express server) so I don't know why there would be a difference in file size.
Your express application has gzip compression enabled as indicated by the Content-Encoding: gzip header, so the response body is compressed with gzip before sending over the network. Transferred size is when compressed, and size is decompressed in the browser. Express is doing this on the fly, so even though your file is not compressed on disk, it gets compressed before it is sent over the network.
Follow-up on your comments
You haven't posted any code, but it's probable that your express application is using the compression middleware (perhaps from the boilerplate you started with). If so, that will use mime-db to determine if the response content type is compressible. Looking up application/javascript in mime-db reveals it is marked as compressible:
mimeDb['application/javascript']
{ source: 'iana',
charset: 'UTF-8',
compressible: true,
extensions: [ 'js' ] }
Note that a .gz file extension is not involved anywhere here. There is no .gz file on disk, the compression is being done to a .js file in memory. Also note that just setting the Content-Encoding: gzip header without actually encoding the body as gzip is not something you want to do. It will cause encoding errors for the client.

AWS S3 Returns 200ok parser fails if ContentEncoding: 'gzip'

My first deploy to AWS.
The files are all in place, and index.html loads.
There are two files in a subdir, one .js and once .css.
They both return 200 but fail to load. Chrome sais it's the 'parser'.
After trying a few things, I noted that this property is causing it: ContentEncoding: "gzip".
If I remove this property the files are found correctly.
Am I using this property incorrectly?
I am using the Node AWS SDK via this great project: https://github.com/MathieuLoutre/grunt-aws-s3
You can witness this behavior for yourself at http://tidepool.co.s3-website-us-west-1.amazonaws.com/
If you specify Content-Encoding: gzip then you need to make sure that the content is actually gzipped on S3.
From what I see in this CSS file:
http://tidepool.co.s3-website-us-west-1.amazonaws.com/08-26_6483218-dirty/all-min.css
the actual content is not gzipped, but the Content-Encoding: gzip header is present.
Also keep in mind that S3 is unable to compress your content on the fly based on the Accept-Encoding header in the request. You can either store it uncompressed and it will work for all browsers/clients or store it in a compressed format (gzip/deflate) and it will only work on some clients that can work with compressed content.
You could also take a look at the official AWS SDK for Node.js.

Serving a static file with servicestack

How would i go around serving a static file using servicestack?
I would like to add a route like Routes.Add(/app) and when a client issues a GET for this path i need to return the a silverlight xap file.
ServiceStack is already be able to serve static files by referencing them directly.
Otherwise if you want a service return a file for downloading, you can do so with:
return new HttpResult(new FileInfo("~/app.xap"), asAttachment:true) {
ContentType = "application/x-silverlight-app"
};
Note: asAttachment will control whether or not to send HTTP Content-Disposition headers.
More info about ServiceStack's responses is in this earlier question: ServiceStack and returning a stream

Resources