Karate: multipart-file is not sent correctly when retrying

Created on 13 Dec 2019  路  3Comments  路  Source: intuit/karate

What's occurred?

  • Content-Length is different among HTTP requests in retry. (please refer logs below)
  • From SUT side, seems multipart-file is not sent correctly when retrying.

1st request:

11:21:07.475 [main] DEBUG com.intuit.karate - request:
1 > POST http://127.0.0.1:8080/files
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Content-Length: 6900
1 > Content-Type: multipart/form-data; boundary=qLIkMvpp9P5si91hYrhG_r4bYyzz8k
1 > Host: 127.0.0.1:8080
1 > User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_192)

2nd request:

11:21:07.512 [main] DEBUG com.intuit.karate - retry condition not satisfied: responseStatus == 201
11:21:07.512 [main] DEBUG com.intuit.karate - sleeping before retry #1
11:21:10.518 [main] DEBUG com.intuit.karate - request:
2 > POST http://127.0.0.1:8080/files
2 > Accept-Encoding: gzip,deflate
2 > Connection: Keep-Alive
2 > Content-Length: 392
2 > Content-Type: multipart/form-data; boundary=2l1ScrvdtQMXwwCL6iQXevXGG233th6x
2 > Host: 127.0.0.1:8080
2 > User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_192)

3rd request:

11:21:10.527 [main] DEBUG com.intuit.karate - retry condition not satisfied: responseStatus == 201
11:21:10.527 [main] DEBUG com.intuit.karate - sleeping before retry #2
11:21:13.532 [main] DEBUG com.intuit.karate - request:
3 > POST http://127.0.0.1:8080/files
3 > Accept-Encoding: gzip,deflate
3 > Connection: Keep-Alive
3 > Content-Length: 407
3 > Content-Type: multipart/form-data; boundary=H3_2pZDfJxEINPqdQyByhNbSkd3WHhiQumRbj
3 > Host: 127.0.0.1:8080
3 > User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_192)

How to reproduce

We can test with modifying upload.feature in karate-demo.
r.f. my example

Expectation

retry sends same HTTP request with multipart-file.

Investigation and Hypothesis

(Sorry I couldn't confirm actually because don't know how to set up Karate development environment)

  • multipart-file data is received and set to HttpEntity as InputStream for building HTTP Request.
  • Once data in the stream was read, cannot be read again when retrying.
  • Thus, 2nd and further retried requests cannot send file data and Content-Length is shorter than 1st.
bug fixed

All 3 comments

@IsaoTakahashi

Once data in the stream was read, cannot be read again when retrying.

yes most likely that is the problem, let me look at it - thanks for being so detailed !

@IsaoTakahashi this is fixed in develop

released 0.9.5

Was this page helpful?
0 / 5 - 0 ratings