# Chunked Encoding

**URL:** <https://community.gatling.io/t/chunked-encoding/298>\
**Category:** Gatling (Open-Source)\
**Created:** [March 17, 2013, 3:51pm UTC](https://community.gatling.io/t/chunked-encoding/298 "2013-03-17T15:51:18Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javier\_Arrieta](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Javier\_Arrieta](https://community.gatling.io/u/Javier_Arrieta)\
**Post date:** [March 17, 2013, 3:51pm UTC](https://community.gatling.io/t/chunked-encoding/298/1 "2013-03-17T15:51:18Z")

</div>

Hi,

I’ve spent some time to figure out how to configure the Http Client to use chunked encoding. I’ve tried setting the header Transfer-Encoding: chunked

My code is

val scn = scenario(“My scenario”)  
.exec(http(“Upload”)  
.post(“[http://192.168.212.71:9080/file](http://192.168.212.71:9080/file)”)  
.header(“Transfer-Encoding”, “chunked”)  
.fileBody(“payload.bin”)  
)

But the requests are not chunked.

Any way to set the request to use chunked encoding?

Thanks!

Javier

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [March 18, 2013, 8:12am UTC](https://community.gatling.io/t/chunked-encoding/298/2 "2013-03-18T08:12:28Z")

</div>

Hi,

Strange, it should work.  
What’s your file’s size? AHC chunks size is hardcoded with a 8ko value.

Stéphane

---

<div class="post-metadata">

**Author:** ![Javier\_Arrieta](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Javier\_Arrieta](https://community.gatling.io/u/Javier_Arrieta)\
**Post date:** [March 19, 2013, 8:02pm UTC](https://community.gatling.io/t/chunked-encoding/298/3 "2013-03-19T20:02:13Z")

</div>

Hi Stéphane,

the file is 50 MB,I’ve also tried with 30MB with the same results. If I use curl I get a correct chunked encoding transfer:

javier@gatling:~/gatling-charts-highcharts-1.4.4$ curl -v -X POST -H “Transfer-Encoding: chunked” -i --data-binary @user-files/request-bodies/payload.bin [http://192.168.212.71:9080/file](http://192.168.212.71:9080/file)

- About to connect() to 192.168.212.71 port 9080 (#0)
- Trying 192.168.212.71… connected

> POST /file HTTP/1.1  
> User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3  
> Host: 192.168.212.71:9080  
> Accept: _/_  
> Transfer-Encoding: chunked  
> Content-Type: application/x-www-form-urlencoded  
> Expect: 100-continue

\< HTTP/1.1 100 Continue  
HTTP/1.1 100 Continue

\< HTTP/1.1 201 Created  
HTTP/1.1 201 Created  
\< Server: spray-can/1.1-M7  
Server: spray-can/1.1-M7  
\< Date: Tue, 19 Mar 2013 20:01:25 GMT  
\< Content-Length: 0  
Content-Length: 0

\<

- Connection #0 to host 192.168.212.71 left intact
- Closing connection #0

Thanks!

Javier

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [March 19, 2013, 8:48pm UTC](https://community.gatling.io/t/chunked-encoding/298/4 "2013-03-19T20:48:33Z")

</div>

Hi Javier,

Would you by any chance a sample to share so I could reproduce, please?  
This would save me a lot of time…

Stéphane

---

<div class="post-metadata">

**Author:** ![Javier\_Arrieta1](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@Javier\_Arrieta1](https://community.gatling.io/u/Javier_Arrieta1)\
**Post date:** [March 19, 2013, 9:05pm UTC](https://community.gatling.io/t/chunked-encoding/298/5 "2013-03-19T21:05:49Z")

</div>

Hi

Do you mean the scenario? Because it is in the first post. Adding it again, it is very simple. The file is generated randomly with dd (dd if=/dev/urandom of=payload.bin bs=50M count=1)

The server is in github (also very simple spray can server):  
[https://github.com/javierarrieta/spray-spikes/tree/master/examples/http-server-example](https://github.com/javierarrieta/spray-spikes/tree/master/examples/http-server-example)

The scenario:

import com.excilys.ebi.gatling.core.Predef.\_  
import com.excilys.ebi.gatling.http.Predef.\_  
import com.excilys.ebi.gatling.jdbc.Predef.\_  
import akka.util.duration.\_  
import bootstrap.\_  
import assertions.\_

class FileUploadSimulation extends Simulation {  
// your code starts here  
val scn = scenario(“My scenario”)  
.exec(http(“Upload”)  
.post(“[http://192.168.212.71:9080/file](http://192.168.212.71:9080/file)”)  
.header(“Transfer-Encoding”, “chunked”)  
.fileBody(“payload.bin”)  
)

setUp(scn.users(18))  
// your code ends here  
}

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [March 19, 2013, 9:29pm UTC](https://community.gatling.io/t/chunked-encoding/298/6 "2013-03-19T21:29:41Z")

</div>

Perfect! Will try tomorrow.

Thanks!

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [March 20, 2013, 12:40pm UTC](https://community.gatling.io/t/chunked-encoding/298/7 "2013-03-20T12:40:06Z")

</div>

OK, got it.

First, chunked transfer encoding is to be used when the Content-Length is unknown. This is available in AHC when providing a body in the form of an InputStream. We don’t currently expose it in Gatling as we haven’t seen a use case for it. In the case of a file, the Content-Length is perfectly known and AHC will perform a zero-copy and directly write on the Socket from the file.

Then, I think your spray-can sample uses the default BufferingRequestStreamActor that buffers the chunks before handling a full HttpRequest to your HttpServiceActor, so you’ll never match chunk events there. See [https://github.com/spray/spray-can#receiving-chunked-requests](https://github.com/spray/spray-can#receiving-chunked-requests)

Cheers,

Stéphane

---

<div class="post-metadata">

**Author:** ![Javier\_Arrieta1](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@Javier\_Arrieta1](https://community.gatling.io/u/Javier_Arrieta1)\
**Post date:** [March 20, 2013, 12:46pm UTC](https://community.gatling.io/t/chunked-encoding/298/8 "2013-03-20T12:46:09Z")

</div>

Hi

Thanks for the info. So for this to work I should modify gatling to accept an InputStream.

The spray-can is working for chunked-encoded requests, it is not aggregating them but creating the correct messages (ChunkedRequestStart, MessageChunk and ChunkedMessageEnd) because of the configuration:

request-chunk-aggregation-limit = 0

I wish I had more time to get a bit deeper in gatling internals. I will try to explore the options for the inputStream

Thanks Stéphane,

Javier

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [March 20, 2013, 12:50pm UTC](https://community.gatling.io/t/chunked-encoding/298/9 "2013-03-20T12:50:44Z")

</div>

My bad, so that might not be the problem.  
I will dig deeper as soon as I find time…

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [March 20, 2013, 12:57pm UTC](https://community.gatling.io/t/chunked-encoding/298/10 "2013-03-20T12:57:34Z")

</div>

Ah, I realized that src/main/resources wasn’t in my classpath (don’t ask me why…).  
Will check again ASAP.

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [March 20, 2013, 1:41pm UTC](https://community.gatling.io/t/chunked-encoding/298/11 "2013-03-20T13:41:20Z")

</div>

I’ve introduced an inputStreamBody in Gatling 2/master, and I confirm that the body gets indeed chunked and that Spray actor gets the Chunk messages.

Stéphane

---

<div class="post-metadata">

**Author:** ![Javier\_Arrieta1](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@Javier\_Arrieta1](https://community.gatling.io/u/Javier_Arrieta1)\
**Post date:** [March 20, 2013, 1:42pm UTC](https://community.gatling.io/t/chunked-encoding/298/12 "2013-03-20T13:42:40Z")

</div>

Thanks!

I will try it as soon as I can and post the results

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [March 20, 2013, 1:45pm UTC](https://community.gatling.io/t/chunked-encoding/298/13 "2013-03-20T13:45:38Z")

</div>

Beware that at this point, the feature is only for Gatling 2, and there’s quite a few things that have changed and are not documented yet…
