question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image passed through handler loses Content-Type

See original GitHub issue

I am using the most recent (June 2019) version of the Serverless Image Handler. I have a bucket set up with source images. Here is an example of the headers returned from an image in the source bucket:

$ curl --head https://hijinnks-images.s3.amazonaws.com/3MODIaQ6oMzipQjW8BJltHaP6ra9mijhCA4Nkh7kP0U.png
HTTP/1.1 200 OK
x-amz-id-2: avRA+ztvXve8GcRi9hUl/qVaGexG2+MaCF2wDyUw9DHkqAt0clC5CxqqJ7EkWpuDGKWL4OOX2qY=
x-amz-request-id: 94E65A7B90E31B32
Date: Sun, 16 Jun 2019 06:08:11 GMT
Last-Modified: Fri, 14 Jun 2019 09:40:02 GMT
ETag: "026e65d25892062bf186de4917975615"
Accept-Ranges: bytes
Content-Type: image/png
Content-Length: 230040
Server: AmazonS3

As you can see, the Content-Type header is correctly reported as image/png. However, if I ask for the image via the Cloudfront Distribution in front of the Serverless Image Handler pipeline, the Content-Type header is incorrectly reported as image with no MIME subtype.

$ curl --head https://d1567g7kv270k0.cloudfront.net/3MODIaQ6oMzipQjW8BJltHaP6ra9mijhCA4Nkh7kP0U.png
HTTP/2 200 
content-type: image
content-length: 311473
date: Sun, 16 Jun 2019 06:05:45 GMT
x-amzn-requestid: c777ac00-8ffc-11e9-b697-f31138bb4941
access-control-allow-origin: *
access-control-allow-headers: Content-Type, Authorization
x-amz-apigw-id: bW9Y8GesIAMFYMQ=
access-control-allow-methods: GET
x-amzn-trace-id: Root=1-5d05dc39-ab9c2724dbab732dce1bba5a;Sampled=0
access-control-allow-credentials: true
age: 170
x-cache: Hit from cloudfront
via: 1.1 b052e5b910437a7391e6af4158f04edb.cloudfront.net (CloudFront)
x-amz-cf-pop: LAX3-C2
x-amz-cf-id: qQrq31i5BCo393UQA3r2108FNDzcMJLU2X66yO36TtXEBIK62K06EA==

The above URL is for the unmodified version of the image. The same problem occurs when I append a Base64-encoded Sharp request for cropping to 400x300. The Content-Type field is also incorrectly reported as image:

$ curl --head https://d1567g7kv270k0.cloudfront.net/eyJidWNrZXQiOiJoaWppbm5rcy1pbWFnZXMiLCJrZXkiOiIzTU9ESWFRNm9NemlwUWpXOEJKbHRIYVA2cmE5bWlqaENBNE5raDdrUDBVLnBuZyIsImVkaXRzIjp7InJlc2l6ZSI6eyJ3aWR0aCI6NDAwLCJoZWlnaHQiOjMwMH19fQ==
HTTP/2 200 
content-type: image
content-length: 230931
date: Sun, 16 Jun 2019 06:11:16 GMT
x-amzn-requestid: 8cc0209e-8ffd-11e9-af2e-8def4168eff4
access-control-allow-origin: *
access-control-allow-headers: Content-Type, Authorization
x-amzn-remapped-content-length: 230931
x-amz-apigw-id: bW-MqGbgIAMFT2A=
access-control-allow-methods: GET
x-amzn-trace-id: Root=1-5d05dd84-90c77daf49feb2fd9aa96531;Sampled=0
access-control-allow-credentials: true
x-cache: Miss from cloudfront
via: 1.1 bd310f631d1314e239dc9cd04967c61f.cloudfront.net (CloudFront)
x-amz-cf-id: V_G1bM04mkbz5DnCDJxqzqGbO074iiS2BJIncpMlfv-WIy46RnunJg==

This error does not appear to be dependent on the image type. Here is a JPEG from the same bucket:

$ curl --head https://hijinnks-images.s3.amazonaws.com/-c1iN7Rj6z3nflyiYzHmOn2C2WcNF57Elq1AtVBlBlA.jpg
...
Content-Type: image/jpeg
...

And the same JPEG delivered through the handler:

$ curl --head https://d1567g7kv270k0.cloudfront.net/-c1iN7Rj6z3nflyiYzHmOn2C2WcNF57Elq1AtVBlBlA.jpg
...
content-type: image
...

This appears to be a new issue introduced with the latest version of the Serverless Image Handler— this problem did not occur previously.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
beomseokleecommented, Feb 6, 2020

We have updated our solution, and I believe your issue has been fixed. If you still see the issue with the latest version (v4.2), please feel free to reopen the issue.

You can refer to the recent changes here

0reactions
ofir-shapira-comocommented, Jan 8, 2020

Hi, this issue also breaks common libraries like .NET Core HttpClient, in addition to Facebook’s crawlers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Image passed through handler loses Content-Type · Issue #103
I am using the most recent (June 2019) version of the Serverless Image Handler. I have a bucket set up with source images....
Read more >
How to make an image handler in NancyFx - Stack Overflow
I basically just want to return image/jpeg from a byte array stored in my database and out put it to the web rather...
Read more >
Handle content types - Azure Logic Apps - Microsoft Learn
Learn how to handle various content types in workflows during design time and run time in Azure Logic Apps.
Read more >
RFC1341(MIME) : 7 The Multipart content type
"X-" fields may be created for experimental or private purposes, with the recognition that the information they contain may be lost at some...
Read more >
HTTP API V2 - Docker Documentation
Company X's build servers lose connectivity to docker registry before completing an image layer transfer. After connectivity returns, the build server ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found