Bug 42158 - Improve support for multipart/form-data requests in HTTP Proxy server
Summary: Improve support for multipart/form-data requests in HTTP Proxy server
Alias: None
Product: JMeter
Classification: Unclassified
Component: HTTP (show other bugs)
Version: 2.2
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
Depends on:
Reported: 2007-04-18 04:21 UTC by Alf Hogemark
Modified: 2007-04-19 14:05 UTC (History)
0 users

Suggested patch (21.72 KB, patch)
2007-04-18 04:23 UTC, Alf Hogemark
Details | Diff
Updated patch (21.82 KB, patch)
2007-04-18 05:07 UTC, Alf Hogemark
Details | Diff
Updated patch (22.92 KB, patch)
2007-04-18 05:24 UTC, Alf Hogemark
Details | Diff
Updated patch (25.08 KB, patch)
2007-04-18 23:07 UTC, Alf Hogemark
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alf Hogemark 2007-04-18 04:21:16 UTC
The code in MultipartUrlConfig.java that currently handles the parsing of
multipart/form-data request is vunerable.
If a multipart section contains any header except "Content-Disposition:
form-data;", for example a "Content-Type: text/plain", the parsing uses
everything after the first headerline as the value of the form parameter.

The same problem is present for file uploads

I suggest to add support for having any headers in the multipar sections.
Comment 1 Alf Hogemark 2007-04-18 04:23:31 UTC
Created attachment 19988 [details]
Suggested patch

This suggested patch uses regular expression to find values for headers we need
during parsing of multipart sections. Headers which are not used, are ignored.
This patch also sets the value for the parameter correctly.

This patch also adds a number of unit tests for parsing of http posting of
multipart/form-data and file uploads.
Comment 2 Alf Hogemark 2007-04-18 05:07:53 UTC
Created attachment 19989 [details]
Updated patch

Same patch as above, but add if test to only set file parameters in sampler, if
a file name is present. If you have a form with both fields and file upload
fields, then there will be multipart section for the the file upload fields,
with filename="" if you do not specify a file for it. It is only confusing to
set the mime type and file field values in the sampler in this case.
Comment 3 Alf Hogemark 2007-04-18 05:24:29 UTC
Created attachment 19990 [details]
Updated patch

This updated patch adds the private method addNonEncodedArgument, so that in
the sampler that is put into the test plan, the "Encode?" checkbox is off.
A multipart/form-data request that is sent by Jmeter does not use the "Encode?"
setting at all, because multipart/form-data values are not url encoded.
So I think it is less likely to confuse the user if the checkbox is always off.
Comment 4 Sebb 2007-04-18 14:49:00 UTC
The test case testPostMultipartFormData() fails the checkArgument() tests - 
the arg.isAlwaysEncoded() comparisons fail. I'm not sure if this is a test 
error or a bug ...
Comment 5 Alf Hogemark 2007-04-18 23:07:16 UTC
Created attachment 19995 [details]
Updated patch

I'm sorry, but I forgot to update the unit tests after the last minute change
to add the private method addNonEncodedArgument.

I have now updated the unit tests, because the "Encode?" will always be false
now, for multipart/form-data requests.

I have also included an unrelated change to the
TestHTTPSamplersAgainstHttpMirrorServer, which was lost when patches where
applied for it yesterday.
Comment 6 Sebb 2007-04-19 14:05:20 UTC
Thanks - applied to SVN in r530547