Skip to content

Add support for multipart/form-data requests***#704

Open
ziyacivan wants to merge 9 commits intojazzband:masterfrom
ziyacivan:add_multipart_support
Open

Add support for multipart/form-data requests***#704
ziyacivan wants to merge 9 commits intojazzband:masterfrom
ziyacivan:add_multipart_support

Conversation

@ziyacivan
Copy link
Copy Markdown

Title: Add Support for Multipart/Form-Data Requests
Description: I've encountered an issue when Silk attempts to handle multipart/form-data requests, specifically
when trying to access request.body directly. This operation triggers a RawPostDataException because Django consumes the stream upon parsing the multipart data, making it inaccessible afterwards.

To address this, I've implemented a check for multipart/form-data content type within the request handling logic. When such a content type is detected, the code now properly handles form data and file information using request.POST and request.FILES, avoiding direct access to request.body. This allows Silk to gracefully handle and log multipart requests without raising exceptions.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 6, 2024

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.56%. Comparing base (5577dd3) to head (212b987).
⚠️ Report is 105 commits behind head on master.

Files with missing lines Patch % Lines
silk/model_factory.py 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #704      +/-   ##
==========================================
- Coverage   86.76%   86.56%   -0.20%     
==========================================
  Files          52       52              
  Lines        2115     2121       +6     
==========================================
+ Hits         1835     1836       +1     
- Misses        280      285       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +229 to +238
content_type = self.request.content_type

if content_type.startswith('multipart/form-data'):
body = {
'form_data': self.request.POST.dict(),
'files': {f: self.request.FILES[f].name for f in self.request.FILES}
}
raw_body = None # Raw body is not available for multipart/form-data
else:
body, raw_body = self.body()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ziyacivan Good catch, and thank you for making this patch! 👏🏼

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh thank you so much! I couldn't continue to the development process (means is tests) because of my social life issues, thank you again 👏🏽

50-Course and others added 2 commits March 25, 2024 18:44
This test-patch addresses the newly updated patch changes when dealing
with `multipart/form_data` request
@50-Course
Copy link
Copy Markdown
Member

50-Course commented Mar 25, 2024

Just found out six different test are failing, I do have to fix them by tomorrow.
By the way, you are welcome to update the test cases if you want to.

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

Successfully merging this pull request may close these issues.

2 participants