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

Variable replacement doesn't work when file is injected in multipart/form-data request #258

Closed
wiadam opened this issue Feb 2, 2024 · 2 comments

Comments

@wiadam
Copy link

wiadam commented Feb 2, 2024

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):

# 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"
}

Functional case

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"
}

Variables file

Content of ./workdir/variables.http is following:

@projectName=test
@AnWeber
Copy link
Owner

AnWeber commented Feb 2, 2024

@AnWeber
Copy link
Owner

AnWeber commented Feb 2, 2024

@wiadam thx for your contribution. I released a new version containing the fix.

@AnWeber AnWeber closed this as completed Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants