Kong / Kong/httpsnippet

Specifying file mime type for multipart requests using python requests module

Open
#302 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.2k
Forks
242
PR merge metrics
No merged PRs in 30d

Description

I'm unable to specify the mime type of the files sent as part of `multipart/form-data` requests using the python requests module.

I believe the relevant code is here: https://github.com/Kong/httpsnippet/blob/master/src/targets/python/requests/client.ts#L82

I was thinking we could support it by making a change like so:

```javascript
if (p.fileName) {
if (p.mimeType) {
files[p.name] = `('${p.fileName}', open('${p.fileName}', 'rb'), '${p.mimeType}')`;
} else {
// current behaviour
files[p.name] = `open('${p.fileName}', 'rb')`;
}
hasFiles = true;
} else {
payload[p.name] = p.value;
hasPayload = true;
}
```

Contributor guide

Open the contributing guide

Research direction

Start in src/targets/python/requests/client.ts around line 82 and inspect how multipart files are assembled for Python requests snippets. Compare the current file handling with the proposed MIME-type behavior, then check nearby tests or target fixtures if present. Done means a file parameter with a MIME type produces the requested multipart tuple while existing file and payload handling remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript
Domain
api, tooling
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.