-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
K6 Does not respect the boundary value placed in a Content-Type header #843
Comments
The workaround is to just not specify a Content-Type, K6 then automatically generates one with the correct boundary definition. |
Thanks, you're right, we should fix this at the same time we fix #747, since both issues are very connected! |
In the case that I MUST change manually the 'Content-type' and then add a random boundary value doesn't work. My scenario is:
K6 still complaining of |
@IsabelaPastorini Could you try this workaround suggested in #1571? Unfortunately you might need to build the entire body manually, or create it outside of k6 and load the binary that way. This issue is in our backlog, but I can't say an ETA for a fix, as other issues currently have higher priority. Sorry for the inconvenience! |
It worked fine! Unfortunately pdf file converted to base64 is to big, so I setUp random data like "123" to convert and worked, Thanks or the suggestion.
Creates a new |
Hey guys, just a heads-up: multipart requests should be simpler to make now with the |
For pdf i still using the #1571 . Can you suggest how can I use Form Data to deal with pdf? I read a little about it and converting the file to binary still needed (?), other wise I receive the error:
|
Hi @IsabelaPastorini , this is supported only since k6 v0.30.0, and from the error message, it seems you are using an earlier version. Can you confirm that and if not, upgrade and retry? |
I will try |
Still doesn't working... My approach is correct? |
@IsabelaPastorini Make sure you're opening the file as binary (with the 'b' argument). See the example and again make sure you're using k6 v0.30.0. Otherwise let us know what's not working... Any errors? It's not the most efficient polyfill, so that can probably be improved, but it works, I just tested it with a PDF. |
Below there is my code, i've checked more than once more that the k6 version is v0.30.0, the bug occurs when I do the http.post. I can read the
|
What bug? Again, let us know the exact error you're getting, otherwise we can't help you. :) I tested with the same example you posted, and there were no errors. Here's the full runnable script: import http from 'k6/http';
import { check } from 'k6';
import { FormData } from 'https://jslib.k6.io/formdata/0.0.1/index.js';
const pdf_file = open('test.pdf','b');
export default function() {
const fd = new FormData();
fd.append('pdf-file', http.file(pdf_file, 'test.pdf', 'application/pdf'));
let url = 'https://httpbin.test.k6.io/post';
let res = http.post(url, fd.body(),
{ headers: { 'Content-Type': 'multipart/form-data; boundary=' + fd.boundary }});
check(res, {
'is status 200': (r) => r.status === 200,
});
} Running
I snipped the binary and base64 data, but be careful with |
The FormData polyfill resolves this issue, and is the recommended way to submit multipart requests, so I'll close this issue. In the future, we might integrate FormData into k6 as part of the new HTTP API (initial design document), but we haven't decided on the details yet. |
If you specify a Context-Type header for a multipart form with a specific boundary, it is ignored:
When looking at the logged request, you get:
Note that the boundary separator is not the one specified in the Content-Type. This results in clients being unable to parse the payload because it can't find the specified boundary.
I would suggest this is linked to #747
The text was updated successfully, but these errors were encountered: