Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JMeter failing for multipart/form body #137

Closed
rplati opened this issue Apr 6, 2020 · 5 comments
Closed

JMeter failing for multipart/form body #137

rplati opened this issue Apr 6, 2020 · 5 comments
Assignees
Milestone

Comments

@rplati
Copy link

rplati commented Apr 6, 2020

Hi, first of all thanks for your work on this package! I got it working and it looks very promising.

I was unable to test my API with JMeter due to tests failing when the API accepts multipart/form data.

I suspect this might be because the boundary that JMeter uses that does not start with double dash signs (--). It seems parse_multipart_body cannot handle that. When I submit the same call with Postman (boundary starts with --), everything works.

Partial JMeter log:

2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "POST /processData HTTP/1.1[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "Connection: keep-alive[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "Content-Length: 708[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "Content-Type: multipart/form-data; boundary=ZI6zx6lhyfOL4qenewl6bZazXipXjA6nR31oGZ6[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "Host: 127.0.0.1:5015[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "User-Agent: Apache-HttpClient/4.5.10 (Java/1.8.0_201)[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "--ZI6zx6lhyfOL4qenewl6bZazXipXjA6nR31oGZ6[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "Content-Disposition: form-data; name="rules"; filename="rules.txt"[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "Content-Type: text/plain[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "Content-Transfer-Encoding: binary[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "descriptionCleaned = str_trim(description),[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "volume = ifelse(str_trim(description) == 'prism', round(baseArea * height, 2), ifelse(str_trim(description) == 'pyramid', round(baseArea * height / 3, 2), NA))"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "--ZI6zx6lhyfOL4qenewl6bZazXipXjA6nR31oGZ6[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "Content-Disposition: form-data; name="dta"; filename="geo.csv"[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "Content-Type: text/csv[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "Content-Transfer-Encoding: binary[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> ""description","baseArea","height"[\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> ""  X",93.3,12.21[\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> ""pyramid",32.9,7.38[\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> ""  prism ",51.1,26.98[\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> ""pyramid",45.7,9.15[\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.h.wire: http-outgoing-44 >> "--ZI6zx6lhyfOL4qenewl6bZazXipXjA6nR31oGZ6--[\r][\n]"
2020-04-06 09:27:03,663 DEBUG o.a.j.p.h.s.HTTPHC4Impl: Sent 945 bytes
2020-04-06 09:27:03,669 DEBUG o.a.h.wire: http-outgoing-44 << "HTTP/1.1 500 Evaluation error[\r][\n]"
2020-04-06 09:27:03,669 DEBUG o.a.h.wire: http-outgoing-44 << "Connection: close[\r][\n]"
2020-04-06 09:27:03,669 DEBUG o.a.h.wire: http-outgoing-44 << "Content-type: text/plain[\r][\n]"
2020-04-06 09:27:03,669 DEBUG o.a.h.wire: http-outgoing-44 << "[\r][\n]"
2020-04-06 09:27:03,669 DEBUG o.a.h.wire: http-outgoing-44 << "Error in parse_multipart_body(body, paste0("--", boundary)) : [\n]"
2020-04-06 09:27:03,669 DEBUG o.a.h.wire: http-outgoing-44 << "  Boundary string not found.[\n]"
2020-04-06 09:27:03,669 DEBUG o.a.h.headers: http-outgoing-44 << HTTP/1.1 500 Evaluation error
2020-04-06 09:27:03,669 DEBUG o.a.h.headers: http-outgoing-44 << Connection: close
2020-04-06 09:27:03,669 DEBUG o.a.h.headers: http-outgoing-44 << Content-type: text/plain

@rplati rplati added bug not-confirmed not-confirmed bugreport labels Apr 6, 2020
@artemklevtsov artemklevtsov self-assigned this Apr 6, 2020
@artemklevtsov artemklevtsov added core and removed not-confirmed not-confirmed bugreport labels Apr 6, 2020
@artemklevtsov artemklevtsov changed the title [BUG] Testing with JMeter failing for multipart/form JMeter failing for multipart/form body Apr 6, 2020
@artemklevtsov
Copy link
Collaborator

artemklevtsov commented Apr 8, 2020

Seems Rserve convert the boundary string to lower case when write the body content-type atrribute. Example:

curl -v \
     -X POST \
     -H "Content-Type: multipart/form-data; boundary=AAAAA" \
     -d $'--AAAAA\r\nContent-Disposition: form-data; name="example"\r\n\r\ntest\r\n--AAAAA--\r\n' \
     http://127.0.0.1:8001

From the Rserve:

HEADERS:
Request-Method: POST
Host: 127.0.0.1:8001
User-Agent: curl/7.69.1
Accept: */*
Content-Type: multipart/form-data; boundary=AAAAA
Content-Length: 76
QUERY:
 NULL
BODY:
 raw [1:76] 2d 2d 41 41 ...
 - attr(*, "content-type")= chr "multipart/form-data; boundary=aaaaa"

JMeter use uppercase symbols in the boundary. parse_multipart_body tries to exact match it.

But Content-Type header is ok. So we should use it.

@artemklevtsov
Copy link
Collaborator

With inst/examples/echo/app.R from the #139:

curl -v -H "Content-Type: multipart/form-data; boundary=AAAAA" -d $'--AAAAA\r\nContent-Disposition: form-data; name="example"\r\n\r\ntest\r\n--AAAAA--\r\n' http://127.0.0.1:8080/echo
*   Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> POST /echo HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.69.1
> Accept: */*
> Content-Type: multipart/form-data; boundary=AAAAA
> Content-Length: 76
>
* upload completely sent off: 76 out of 76 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-type: application/json
< Server: RestRserve/0.2.1
< Content-length: 322
<
* Connection #0 to host 127.0.0.1 left intact
{"path":"/echo","headers":{"content-length":"76","host":"127.0.0.1:8080","user-agent":"curl/7.69.1","accept":"*/*","content-type":"multipart/form-data; boundary=AAAAA"},"parameters":{"query":{},"body":{"example":"test"},"path":[]},"body":{"attributes":{"content-type":"multipart/form-data; boundary=aaaaa"},"rtpye":"raw"}}

dselivanov pushed a commit that referenced this issue Apr 9, 2020
* Rename C++ exported functions (add cpp_ prefix)

* Change boundary generation for the tests

* Fix boundary parsing and matching

* Add echo demo app

* Add test for the Request$set_id

* Wrap BackendRserve$start with nocov

* Fill Request content-type from headers only if empty (fix tests fail)

* Use ASCII to generate boundary for the tests

* Simulate Rserve behaviour for multipart body in test
@dselivanov dselivanov removed the Rserve label Apr 9, 2020
@artemklevtsov
Copy link
Collaborator

@rplati, can you test again with dev branch? To install use the following command:

remotes::install_github("rexyai/RestRserve@dev")

@rplati
Copy link
Author

rplati commented Apr 9, 2020

@artemklevtsov, I can confirm that the issue has been resolved, thank you!

@rplati rplati closed this as completed Apr 9, 2020
@dselivanov
Copy link
Collaborator

@rplati on CRAN now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants