0

I have difficulty in understanding how this header works.

Briefly my question is

If i am requesting a post to certain resource then let's Say in 1st case response is some json string and in 2nd case response is a .jar file.

1.Should client include accept-header:gzip,deflate in both cases while sending HTTP request,knowing that first one results in json string?

2.What if the response is already zipped,now zipping the response over the already zipped data doesn't create problems?

3.what happens if i include accept-encoding:gzip in first case where json string is received. So i receive a zipped data as my response(i am not even sure if get zipped data or some encoded data as response.I think zipped data means something zipped like .jar/.zip and encoded data means Encoded data of the original data ,which one is happening zipping or encoding)?

4.Lets say the server sends the response with Contentype header as "application/octet-stream". Now is it must to use accept-header:gzip,deflate

2
  • I assume you mean to say "accept-encoding"? Commented Dec 11, 2017 at 10:10
  • Yes,thanks. Edited it. Commented Dec 11, 2017 at 10:22

2 Answers 2

4

A client can use Accept-Encoding HTTP request header to tell the server that it can accept a compressed response.

The server can use the request header to decide if it should send a compressed response or not. It can ignore the header and always send a non-compressed response (possibly less efficient). It can ignore the header and always send a compressed response (risking giving a client a response it can't decode).

Should client include accept-header:gzip,deflate in both cases

I can't think of any reason to not tell the server that a client can handle a compressed response (assuming that fact is true).

What if the response is already zipped,now zipping the response over the already zipped data doesn't create problems

It might be a waste of processor power for little or no saving in bytes.

That's not a reason for the client to say it can't handle a compressed response though. That's a decision to be made on the server.

what happens if i include accept-encoding:gzip in first case where json string is received.

Then the client has told the server that a compressed response is acceptable.

So i receive a zipped data as my response

The server might send a compressed response. It might ignore the header.

i am not even sure if get zipped data or some encoded data as response

There isn't an "or" here.

The data is encoded using a compression algorithm.

Lets say the server sends the response with Contentype header as "application/octet-stream"

That just means the server doesn't know what type of data it is sending. Instead of saying "This is JSON" or "This is a jar file" it is saying "I dunno what this is, it's just a stream of bytes to me".

Now is it must to use accept-header:gzip,deflate

It doesn't make a difference.

The server can compress the data. It can send uncompressed data. It can use the Accept-Encoding request header to decide which of the two.

Sign up to request clarification or add additional context in comments.

Comments

1
  1. Yes, why not? If the JSON payload is big, compressing it will make a lot of sense.

  2. It's just overhead.

  3. You might receive gzipped data - not a ZIP file. You may want to read RFCs 7230 and RFC 7231 for details.

  4. The internet media type of the payload is completely independent of the content coding.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.