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
create multipart/form-data HTTP request without uploading file #1332
Comments
tshimizu (migrated from Bugzilla): The filename should be acquired from getFilename(). The filename should look like : Thanks, Takuya |
Alf Hogemark (migrated from Bugzilla): This patch adds support for using multipart/form-data even if no file is being More headers are set both on the request, and in the multiparts, for both Also the encoding used are set for the multiparts. Both the HTTPSampler and HTTPSampler2 is changed, so that the "querystring" It changes PostWriter, by changing methods to non-static, i.e. requiring that What I currently do not like about the patch : The HTTPSampler currently provides the full path to the file in the header of I am not 100% confident that I am handling the "httpargument.isalwaysencoded" Conclusion : Created attachment patch_for_27780.patch: Suggested patch |
Alf Hogemark (migrated from Bugzilla): The "testSendPostData_FileAsBody" will also fail for the last test, because the Created attachment patch_for_27780_unit_test_current.patch: Patch for unit test for svn version of PostWriter |
Alf Hogemark (migrated from Bugzilla): This unit tests passes all tests. And it shows that posting of UTF-8 values as part of multipart/form-data works, And it shows that if a HTTPSampler contains both form parameters, and just a Created attachment patch_for_27780_unit_test_new.patch: Unit test for the suggested updated PostWriter / HTTPSampler in patch above |
Alf Hogemark (migrated from Bugzilla): This patch also contains a new class TestHTTPSamplersAgainstHttpMirrorServer, As before, the lines starting with // at the very beginning of the lines, are Created attachment patch_for_27780_unit_test_current_2.patch: Patch for unit test for current svn version of PostWriter |
Alf Hogemark (migrated from Bugzilla): It also contains the TestHTTPSamplersAgainstHttpMirrorServer, where all tests Created attachment patch_for_27780_unit_test_new_2.patch: Updated patch for unit testing for new suggested PostWriter/HTTPSampler/2 |
Alf Hogemark (migrated from Bugzilla): Compared to the previous suggested patch for unit testing og current svn Created attachment patch_for_27780_unit_test_current_3.patch: Updated patch for unit testing of current svn version of PostWriter/HTTPSampler/2 |
Alf Hogemark (migrated from Bugzilla): Compared to the previous suggested patch for unit testing of the suggested new Created attachment patch_for_27780_unit_test_new_3.patch: Updated patch for unit testing for new suggested PostWriter/HTTPSampler/2 |
Sebb (migrated from Bugzilla):
When the above patch is applied, I get 4 test failures: |
Alf Hogemark (migrated from Bugzilla): Since PostWriter/HTTPSampler/2 does not produce multipart/form-data requests, I have also commented out tests in PostWriter for testing sending parameter So if you now apply this patch, all the unit tests should pass. Created attachment patch_for_27780_unit_test_current_4.patch: Updated patch for unit testing of current svn version of PostWriter/HTTPSampler/2 |
Sebb (migrated from Bugzilla): |
Sebb (migrated from Bugzilla): |
Alf Hogemark (migrated from Bugzilla): I have also enabled more of the unit tests in I have also changed the ENCODING of PostWriter to "ISO-8859-1", i.e. uppercase. I have also made a constant HTTP_ENCODING for both PostWriterTest and Created attachment patch_for_27780_2.patch: Fix bug in PostWriter2 for content transfer encoding, and add unit tests |
Sebb (migrated from Bugzilla):
Applied |
Alf Hogemark (migrated from Bugzilla): This patch also changes the HTTP Proxy server, so that if the proxy sees a HTTP If this patch is applied, I think this bug can be closed as "fixed". Created attachment patch_for_27780_user_and_proxy_choose_multipart.patch: Suggested patch to allow user to choose to use multipart/form-data for post, as well as HTTP Proxy server patch_for_27780_user_and_proxy_choose_multipart.patchIndex: C:/Documents and Settings/alf.hogemark/workspace/Jmeter 2.2 official/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
===================================================================
--- C:/Documents and Settings/alf.hogemark/workspace/Jmeter 2.2 official/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java (revision 527881)
+++ C:/Documents and Settings/alf.hogemark/workspace/Jmeter 2.2 official/src/protocol/http/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java (working copy)
@@ -233,17 +233,30 @@
return ""; // $NON-NLS-1$
}
- private MultipartUrlConfig isMultipart(String contentType) {
- if (contentType != null && contentType.startsWith(MultipartUrlConfig.MULTIPART_FORM)) {
- return new MultipartUrlConfig(contentType.substring(contentType.indexOf("oundary=") + 8));
- } else {
- return null;
- }
- }
+ private boolean isMultipart(String contentType) {
+ if (contentType != null && contentType.startsWith(MultipartUrlConfig.MULTIPART_FORM)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ private MultipartUrlConfig getMultipartConfig(String contentType) {
+ if(isMultipart(contentType)) {
+ // Get the boundary string for the multiparts from the
+ // content type
+ //int startOfBoundaryValuePos = contentType.toLowerCase().substring(beginIndex)
+ String boundaryString = contentType.substring(contentType.toLowerCase().indexOf("boundary=") + "boundary=".length());
+ System.out.println("boundaryString " + boundaryString);
+ return new MultipartUrlConfig(boundaryString);
+ }
+ else {
+ System.out.println("Not multipart");
+ return null;
+ }
+ }
+
private void populateSampler() {
- MultipartUrlConfig urlConfig = null;
-
sampler.setDomain(serverName());
if (log.isDebugEnabled())
log.debug("Proxy: setting server: " + sampler.getDomain());
@@ -275,19 +288,23 @@
log.debug("Proxy setting default protocol to: http");
sampler.setProtocol(HTTP);
}
- if ((urlConfig = isMultipart(getContentType())) != null) {
- urlConfig.parseArguments(postData);
- // If no file is uploaded, then it was really a multipart/form-data
- // post request. But currently, that is not supported, so we must
- // change the "Content-Type" header from multipart/form-data to
- // application/x-www-form-urlencoded, which is the one the HTTP Request
- // sampler will send
- if(urlConfig.getFilename() == null) {
- System.out.println("jada");
- getHeaderManager().removeHeaderNamed("Content-Type");
- getHeaderManager().add(new Header("Content-Type", "application/x-www-form-urlencoded"));
- }
- sampler.setArguments(urlConfig.getArguments());
+
+ // Check if it was a multipart http post request
+ MultipartUrlConfig urlConfig = getMultipartConfig(getContentType());
+ if (urlConfig != null) {
+ urlConfig.parseArguments(postData);
+ // Tell the sampler to do a multipart post
+ sampler.setDoMultipartPost(true);
+ // Remove the header for content-type and content-length, since
+ // those values will most likely be incorrect when the sampler
+ // performs the multipart request, because the boundary string
+ // will change
+ getHeaderManager().removeHeaderNamed(CONTENT_TYPE);
+ getHeaderManager().removeHeaderNamed(CONTENT_LENGTH);
+
+ // Set the form data
+ sampler.setArguments(urlConfig.getArguments());
+ // Set the file uploads
sampler.setFileField(urlConfig.getFileFieldName());
sampler.setFilename(urlConfig.getFilename());
sampler.setMimetype(urlConfig.getMimeType());
Index: C:/Documents and Settings/alf.hogemark/workspace/Jmeter 2.2 official/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
===================================================================
--- C:/Documents and Settings/alf.hogemark/workspace/Jmeter 2.2 official/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java (revision 527881)
+++ C:/Documents and Settings/alf.hogemark/workspace/Jmeter 2.2 official/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java (working copy)
@@ -64,6 +64,8 @@
private static String USE_KEEPALIVE = "use_keepalive"; // $NON-NLS-1$
+ private static String USE_MULTIPART_FOR_POST = "use_multipart_for_post"; // $NON-NLS-1$
+
private JTextField domain;
private JTextField port;
@@ -80,6 +82,8 @@
private JCheckBox useKeepAlive;
+ private JCheckBox useMultipartForPost;
+
private JLabeledChoice method;
public UrlConfigGui() {
@@ -102,6 +106,7 @@
protocol.setText(""); // $NON-NLS-1$
contentEncoding.setText(""); // $NON-NLS-1$
useKeepAlive.setSelected(true);
+ useMultipartForPost.setSelected(false);
argsPanel.clear();
}
@@ -122,6 +127,7 @@
element.setProperty(new BooleanProperty(HTTPSamplerBase.FOLLOW_REDIRECTS, followRedirects.isSelected()));
element.setProperty(new BooleanProperty(HTTPSamplerBase.AUTO_REDIRECTS, autoRedirects.isSelected()));
element.setProperty(new BooleanProperty(HTTPSamplerBase.USE_KEEPALIVE, useKeepAlive.isSelected()));
+ element.setProperty(new BooleanProperty(HTTPSamplerBase.DO_MULTIPART_POST, useMultipartForPost.isSelected()));
return element;
}
@@ -152,6 +158,7 @@
autoRedirects.setSelected(((AbstractTestElement) el).getPropertyAsBoolean(HTTPSamplerBase.AUTO_REDIRECTS));
useKeepAlive.setSelected(((AbstractTestElement) el).getPropertyAsBoolean(HTTPSamplerBase.USE_KEEPALIVE));
+ useMultipartForPost.setSelected(((AbstractTestElement) el).getPropertyAsBoolean(HTTPSamplerBase.DO_MULTIPART_POST));
}
protected void init() {
@@ -209,8 +216,8 @@
}
/**
- * This method defines the Panel for the HTTP path, 'Follow Redirects' and
- * 'Use KeepAlive' elements.
+ * This method defines the Panel for the HTTP path, 'Follow Redirects'
+ * 'Use KeepAlive', and 'Use multipart for HTTP POST' elements.
*
* @return JPanel The Panel for the path, 'Follow Redirects' and 'Use
* KeepAlive' elements.
@@ -235,6 +242,10 @@
useKeepAlive.setName(USE_KEEPALIVE);
useKeepAlive.setSelected(true);
+ useMultipartForPost = new JCheckBox(JMeterUtils.getResString("use_multipart_for_http_post")); // $NON-NLS-1$
+ useMultipartForPost.setName(USE_MULTIPART_FOR_POST);
+ useMultipartForPost.setSelected(false);
+
JPanel pathPanel = new JPanel(new BorderLayout(5, 0));
pathPanel.add(label, BorderLayout.WEST);
pathPanel.add(path, BorderLayout.CENTER);
@@ -244,6 +255,7 @@
optionPanel.add(autoRedirects);
optionPanel.add(followRedirects);
optionPanel.add(useKeepAlive);
+ optionPanel.add(useMultipartForPost);
optionPanel.setMinimumSize(optionPanel.getPreferredSize());
JPanel panel = new JPanel();
Index: C:/Documents and Settings/alf.hogemark/workspace/Jmeter 2.2 official/src/core/org/apache/jmeter/resources/messages.properties
===================================================================
--- C:/Documents and Settings/alf.hogemark/workspace/Jmeter 2.2 official/src/core/org/apache/jmeter/resources/messages.properties (revision 527881)
+++ C:/Documents and Settings/alf.hogemark/workspace/Jmeter 2.2 official/src/core/org/apache/jmeter/resources/messages.properties (working copy)
@@ -750,6 +750,7 @@
url_full_config_title=UrlFull Sample
url_multipart_config_title=HTTP Multipart Request Defaults
use_keepalive=Use KeepAlive
+use_multipart_for_http_post=Use multipart/form-data for HTTP POST
use_recording_controller=Use Recording Controller
user=User
user_defined_test=User Defined Test |
Sebb (migrated from Bugzilla): |
Thomas Fischer (Bug 27780):
Hi,
Sometimes a web based application expects to receive a request with content
type multipart/form-data and does not accept a simple post request. A browser
creates a multipart/form-data request even if no file is uploaded, if the user
leaves the upload-field empty. However, with jmeter it is not possible to
create a multipart/form-data request without uploading a file, jmeter just
sends a simple post form. It would be nice if there was a checkbox in the GUI
to create a multipart/form-data request even without uploading a file.
Also, while recording a workflow with a multipart/form-data request without
uploaded file with the jmeter proxy, the proxy resends it as a simple request.
It would be nice if the content-type of the original request would be preserved
in the call by the proxy. Even more problematic is that the HTTP header still
proclaims the sent request to have the content type multipart/form-data, even
if the body does not contain the multipart boundary.
Then, if a file is choosen which is not present in the directory where jmeter
was started, the Jmeter proxy displays a FileNotFoundException in the Browser,
although the proxy is located on the same host as the browser and the full path
was given when selecting the file. To prevent this error, I had to put a file
with the same name in the directory where jmeter was started from. If possible,
it would be nice if the jmeter proxy would use the full path when re-sending
the request to the server. (I don't know enough about proxies: probably the
image is already contained in the request sent by the browser, so it is not
necessary to access the file system again ???)
Cheers, Thomas
Votes in Bugzilla: 3
OS: other
The text was updated successfully, but these errors were encountered: