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

V1.1.0 - Jsondata in Multipart/formdata header APIs defaults to "application/octet-stream" #1710

Closed
MounarajElangovan opened this issue Aug 9, 2021 · 9 comments
Assignees
Milestone

Comments

@MounarajElangovan
Copy link

MounarajElangovan commented Aug 9, 2021

Version: 1.1.0

Problem Statement:
In new version of karate, multipart/formdata header APIs are not working as expected when we send both JSON data and files in same API request. This has been working perfectly in lower version (0.9.6).

JSON data in multipart/formdata requests defaults to "application/octet-stream" and content length is always "0".

Here, when we send files alone in multipart/formdata in new version of karate then it is working fine similar to lower versions (Issue occurs when sending JSON also).

I have attached working copy to replicate this issue along with some screenshots of karate reports with API response to differentiate the behavior in older version and current version for better understanding of the issue.

Attachments:

1. Working copy to replicate this issue in local -
multipart-header-working-copy.zip

Command to run: mvn clean test -Dtest=TestRunner

2. JSON defaults to octetstream screenshot -
defaults-to-octetstream-in-v1 1 0

3. V1.1.0 response screenshot (not expected behavior) -
v1 1 0-response

4. V0.9.6 response screenshot (expected behavior) -
v0 9 6-response

Please check and let me know if you need more information from my side.

@ptrthomas ptrthomas self-assigned this Aug 9, 2021
@ptrthomas ptrthomas added the bug label Aug 9, 2021
@ptrthomas ptrthomas added this to the 1.2.0 milestone Aug 9, 2021
@ptrthomas
Copy link
Member

@MounarajElangovan can you please confirm if this works:

    * def temp = {"name": "mike", "age": 27, "validaccount": true}
    And multipart file jsondata = { value: '#(temp)' }

@MounarajElangovan
Copy link
Author

@ptrthomas - It is working when we define data like this,

Request log for reference:

content-disposition: form-data; name="jsondata"; filename=""
content-type: application/json; charset=UTF-8
content-length: 44
Completed: true
IsInMemory: true

@ptrthomas
Copy link
Member

@MounarajElangovan ok so you are confirming that's a valid workaround ?

@MounarajElangovan
Copy link
Author

@ptrthomas Yes, I am confirming this is as a valid workaround, I have double checked this with my real time test case also. It is working fine with this workaround.

@ptrthomas
Copy link
Member

ptrthomas commented Aug 9, 2021

@MounarajElangovan thanks ! you have solved a mystery that a few users reported and we were not able to figure out. you also have made me realize that httpbin can be used to troubleshoot file upload, thanks !

I've fixed this in develop, do see if you can validate by following the developer guide. but please use the workaround. in fact I am thinking of deprecating multipart field (and mutlipart fields), and you can use multipart file for everything, because you have full control over the content-type for each part.

so for others who land here: if you can't get multipart field to work for non-string values, please use mutipart file like this:

* url "https://httpbin.org/post"
* def temp = {"name": "mike", "age": 27, "validaccount": true}
* multipart file jsondata = { value: '#(temp)' }
* method post

@ptrthomas ptrthomas added the fixed label Aug 9, 2021
@MounarajElangovan
Copy link
Author

@ptrthomas Good morning! Wow! That is great to hear from you. I will try to validate using developer guide. Thanks again for fixing this, it will help us lot. Awesome!

@MounarajElangovan
Copy link
Author

@ptrthomas I have validated in develop branch, it is working fine. Thanks!

@ptrthomas
Copy link
Member

@nbhattr this is the wrong place for questions like this unless you follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue - so please use stack overflow if needed. that said you should probably spend some time reading this: #1645 (comment)

@ptrthomas
Copy link
Member

1.2.0 released

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

2 participants