RejectedSoftware Forums

Sign up

Why does writeJsonBody always set the transfer encoding to chunked?

I'm starting to learn D by writing a client for a RESTful API. I found something that seems wrong to me. When I use writeJsonBody to send my data to the server I receive a 411 error. If I send the same data by setting the content type and length myself it works just fine. So, I pulled up Wireshark and found that the Transfer-Encoding is being set to chunked. Looking at the code for writeJsonBody I see that it always sets the transfer encoding to chunked.

Is there a reason for this? If so, what should I be doing differently?

Re: Why does writeJsonBody always set the transfer encoding to chunked?

Am 30.07.2014 05:42, schrieb David Johnson:

I'm starting to learn D by writing a client for a RESTful API. I found something that seems wrong to me. When I use writeJsonBody to send my data to the server I receive a 411 error. If I send the same data by setting the content type and length myself it works just fine. So, I pulled up Wireshark and found that the Transfer-Encoding is being set to chunked. Looking at the code for writeJsonBody I see that it always sets the transfer encoding to chunked.

Is there a reason for this? If so, what should I be doing differently?

There are two reasons for this:

  • ChunkedOutputStream is still missing an optimization where it
    should use Content-Length if the data to transfer is smaller than the
    chunk size
  • writeJsonBody was discussed to be changed to not directly write to
    the connection, but rather to first write to a special counting range
    and then write again, but to the connection with content-length set.
    This possibly trades a little performance for a simpler protocol.

I'll implement both, since they are easy to do and have been unsolved
for a long time now.

Re: Why does writeJsonBody always set the transfer encoding to chunked?

On Wed, 30 Jul 2014 10:20:51 +0200, Sönke Ludwig wrote:

  • writeJsonBody was discussed to be changed to not directly write to

the connection, but rather to first write to a special counting range
and then write again, but to the connection with content-length set.
This possibly trades a little performance for a simpler protocol.

This has now been implemented: 0ecd891

Re: Why does writeJsonBody always set the transfer encoding to chunked?

On Wed, 30 Jul 2014 09:10:06 GMT, Sönke Ludwig wrote:

On Wed, 30 Jul 2014 10:20:51 +0200, Sönke Ludwig wrote:

  • writeJsonBody was discussed to be changed to not directly write to
    the connection, but rather to first write to a special counting range
    and then write again, but to the connection with content-length set.
    This possibly trades a little performance for a simpler protocol.

This has now been implemented: 0ecd891

That's awesome, what a quick response! Thank you!