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

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ziyacivan
Copy link

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.

Copy link

codecov bot commented Feb 6, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 86.56%. Comparing base (5577dd3) to head (212b987).
Report is 2 commits behind head on master.

Files 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.

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