Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct HTTP Headers for Images?

I'm writing a web server in C#, just for the fun of it, and I am able to serve basic text files to my browser. However, when serving up an image (say, image.png), all browsers that I test my server on (IE, Firefox, and Chrome) show some kind of placeholder thumbnail for the image, as if the image is corrupted or invalid.

The response that I am sending to the browser looks like

HTTP/1.0 200 Ok
Content-Type: image/png
Content-Length: 14580053

{image data here}

Am I using the correct HTTP headers? Or, if I am, why else would browsers not accept the image?

like image 696
feralin Avatar asked Nov 27 '13 16:11

feralin


People also ask

What is the header of an image?

A header image is the picture that appears at the top of a social media profile. Also known as a cover image or cover photo, it provides a chance to showcase your products, your team, or any other aspect of your business that will make people want to explore your profile.

What should be included in HTTP header?

HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its case-insensitive name followed by a colon ( : ), then by its value. Whitespace before the value is ignored.

What is Content-Type for image?

The Content-Type header is used to indicate the media type of the resource. The media type is a string sent along with the file indicating the format of the file. For example, for image file its media type will be like image/png or image/jpg, etc.


1 Answers

Ah, figured it out... my code forgot to add an extra \n before the response body. It wasn't a problem with the headers at all, just incorrect response syntax.

like image 154
feralin Avatar answered Oct 15 '22 21:10

feralin