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

HTTP header names are incorrectly case-sensitive #49

Open
adw3r opened this issue Sep 7, 2023 · 2 comments
Open

HTTP header names are incorrectly case-sensitive #49

adw3r opened this issue Sep 7, 2023 · 2 comments

Comments

@adw3r
Copy link

adw3r commented Sep 7, 2023

it`s just added "Content-Type": "application/x-www-form-urlencoded" to original headers where "content-type": "multipart/form-data; boundary=----WebKitFormBoundarybJcBAJddlZGVXFha"

image
image
image

@rgov
Copy link
Owner

rgov commented Sep 7, 2023

Thanks for your report. In the future can you please copy and paste the code, instead of posting only screenshots? It's hard to reproduce the issue from a screenshot.

There are a few issues here:

  1. Passing --data (or similar) sets the Content-Type header even if content-type is already provided.

    if (!('Content-Type' in req.headers)) {
    req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
    }

    As a workaround, you can change your input to use Content-Type instead of content-type.

  2. Argument parameters that start with - cause an error. This seems consistent with the Python argparse module:

     import argparse
    
     parser = argparse.ArgumentParser()
     parser.add_argument('-x')
     args = parser.parse_args(['-x', '-lol'])  # errors

    According to this StackOverflow answer, you can solve this by adding an = between the argument and its value, like --data-raw=$'-----...'.

I'll update the bug to track fixing item 1. But the error logged for item 2 could be better.

@rgov rgov changed the title Multipart form data Curl to JSON request converts with wrong content-type HTTP header names are incorrectly case-sensitive Sep 7, 2023
@rgov
Copy link
Owner

rgov commented Sep 7, 2023

I should use req.hasHeader('Content-Type').

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