dimanche 3 juin 2018

Laravel missing HTTP header for hot linked images

Even though my actual issue is a little bit far away, I will share it first:

I was using Telegram bot to send images. Telegram API accepts image URLs (they will cache it to their server and do the job). Image files from my server threw an error from Telegram API which is something like this:

Unhandled rejection Error: ETELEGRAM: 400 Bad Request: wrong file identifier/HTTP URL specified

So I did few tests. Tried a link from another server, and another server. All of them works. So I came to the conclusion that my response header for images does not look like the one which is working fine. Here are my tested cases:

  • HTTPS from other server works
  • HTTP from other server works
  • Any image URL from my server throws error from Telegram.

Here are the response headers of working and not working.

Working fine

HTTP/1.0 200 OK
Access-Control-Expose-Headers: Content-Length
ETag: "v4bb"
Expires: Mon, 04 Jun 2018 12:16:17 GMT
Cache-Control: public, max-age=86400, no-transform
Content-Disposition: inline;filename="chotta_mumbai1.jpg"
Content-Type: image/jpeg
Vary: Origin
Access-Control-Allow-Origin: *
Timing-Allow-Origin: *
X-Content-Type-Options: nosniff
Date: Sun, 03 Jun 2018 12:16:17 GMT
Server: fife
Content-Length: 23702
X-XSS-Protection: 1; mode=block

Working fine

HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Sun, 03 Jun 2018 12:18:07 GMT
Content-Type: image/png
Content-Length: 12399
Last-Modified: Fri, 10 Nov 2017 17:54:14 GMT
Connection: close
ETag: "5a05e7c6-306f"
Expires: Thu, 07 Jun 2018 12:18:07 GMT
Cache-Control: max-age=345600
Strict-Transport-Security: max-age=15768000
Accept-Ranges: bytes

Not working

HTTP/1.1 200 OK
Date: Sun, 03 Jun 2018 12:16:50 GMT
Server: Apache/2.4.18 (Ubuntu)
Last-Modified: Wed, 30 May 2018 17:51:56 GMT
ETag: "daf3-56d7001c0390b"
Accept-Ranges: bytes
Content-Length: 56051
Connection: close
Content-Type: image/jpeg

So I came to a conclusion that my response header is not enough for Telegram's API. Any clue how to fix this.?

Currently, my image URL is coming from public directory say:

http://example.com/public/images/zR5AR.jpg



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire