-1

We're setting up a basic http web server using node. We're coding in Java Script if this helps. I don't understand exactly what is being asked of us. Windows using Gitbash.

"Return the file to the user by setting the correct Content-Type for the file and writing it to the response"

That is word for word what is asked in the lab.

If someone could explain I'd appreciate it.

Makoto
  • 104,088
  • 27
  • 192
  • 230
Thomas123
  • 69
  • 1
  • 4
  • [Basics of HTTP: MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types). – Elliott Frisch Sep 16 '18 at 01:41
  • It would be helpful to understand more about what you are actually doing. For example, what OS? What web server? And what Java frameworks? – markspace Sep 16 '18 at 01:44

2 Answers2

1

Whenever someone makes a request to a server, the server answers the request with a header and a body. The body usually contains the data you see on the browser and the header contains information about the type of content the server is returning.

When the server returns a file, it has to set this information on the header, otherwise the browser would expect the content to be just text. This information on the header that describes the content is called Content-Type.

As pointed out by Elliott Frisch, this web page contains a list of the suported mime types that your server should be returning: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types

Danilo Souza Morães
  • 1,481
  • 13
  • 18
1

Basically it's a header sent in the request in addition to the request body. If you're sending say...video content to a server how is it supposed to know that from say an image?

There are several different kinds that can be seen here though usually you don't need content-type headers for things like POCOs, POJOs, and raw text. Here is a list of all the types

What are all the possible values for HTTP "Content-Type" header?

Here is how to change them in a fetch request from react (since you mentioned javascript):

fetch(url, { method: "POST", body: data, headers: { "Content-Type": "application/json" }, credentials: "same-origin" })

this would send a json data payload (you have to turn it into json manually) in a post request.

Also as an aside your post was tagged "java"....javascript and java are not the same thing.

Redmancometh
  • 76
  • 1
  • 11