Closed wiadam closed 5 months ago
When a multipart/form-data request is sent, variables are not replaced in body payload of the request if a file is injected in one part of the form.
It is expected to have variables replaced regardless of what other part is injected in request body. BTW, I find awesome this VSCode extension :)
For following request (with variable AND file injection):
# Import variables # @import ../workdir/variables.http ### POST https://httpbin.org/post Content-Type: multipart/form-data; boundary=WebKitFormBoundary --WebKitFormBoundary Content-Disposition: form-data; name="text" {{projectName}} --WebKitFormBoundary Content-Disposition: form-data; name="invoice"; filename="invoice.pdf" Content-Type: application/pdf < ./dummy.pdf --WebKitFormBoundary--
Response is following
{ "args": {}, "data": "", "files": { "invoice": "1" }, "form": { "text": "{{projectName}}" }, "headers": { "Accept": "*/*", "Accept-Encoding": "gzip, deflate, br", "Content-Length": "238", "Content-Type": "multipart/form-data; boundary=WebKitFormBoundary", "Host": "httpbin.org", "User-Agent": "httpyac", "X-Amzn-Trace-Id": "Root=1-65bc352a-09deb72a513ef6ff60dfffb6" }, "json": null, "origin": "***REDACTED***", "url": "https://httpbin.org/post" }
If request doesn't have file injection, variables replacement work fine. For request (with only variable):
# Import variables # @import ../workdir/variables.http ### POST https://httpbin.org/post Content-Type: multipart/form-data; boundary=WebKitFormBoundary --WebKitFormBoundary Content-Disposition: form-data; name="text" {{projectName}} --WebKitFormBoundary--
Response is:
{ "args": {}, "data": "", "files": {}, "form": { "text": "test" }, "headers": { "Accept": "*/*", "Accept-Encoding": "gzip, deflate, br", "Content-Length": "97", "Content-Type": "multipart/form-data; boundary=WebKitFormBoundary", "Host": "httpbin.org", "User-Agent": "httpyac", "X-Amzn-Trace-Id": "Root=1-65bc357b-7107433c0fd312492c17692b" }, "json": null, "origin": "***REDACTED***", "url": "https://httpbin.org/post" }
Content of ./workdir/variables.http is following:
@projectName=test
Need to change order of these two lines: https://github.com/AnWeber/httpyac/blob/main/src/plugins/core/registerCorePlugin.ts#L28-L29
@wiadam thx for your contribution. I released a new version containing the fix.
Problem description
When a multipart/form-data request is sent, variables are not replaced in body payload of the request if a file is injected in one part of the form.
It is expected to have variables replaced regardless of what other part is injected in request body. BTW, I find awesome this VSCode extension :)
Steps to reproduce
Non functional case
For following request (with variable AND file injection):
Response is following
Functional case
If request doesn't have file injection, variables replacement work fine. For request (with only variable):
Response is:
Variables file
Content of ./workdir/variables.http is following: