View | Details | Raw Unified | Return to bug 42158
Collapse All | Expand All

(-)C:/Documents and Settings/alf.hogemark/workspace/JMeter 2.2 official_2/test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java (-37 / +193 lines)
Lines 20-25 Link Here
20
20
21
import java.io.ByteArrayInputStream;
21
import java.io.ByteArrayInputStream;
22
import java.io.IOException;
22
import java.io.IOException;
23
import java.net.URLEncoder;
23
24
24
import org.apache.jmeter.config.Arguments;
25
import org.apache.jmeter.config.Arguments;
25
import org.apache.jmeter.junit.JMeterTestCase;
26
import org.apache.jmeter.junit.JMeterTestCase;
Lines 43-89 Link Here
43
        // Check arguments
44
        // Check arguments
44
        Arguments arguments = s.getArguments();
45
        Arguments arguments = s.getArguments();
45
        assertEquals(13, arguments.getArgumentCount());
46
        assertEquals(13, arguments.getArgumentCount());
46
        checkArgument((HTTPArgument)arguments.getArgument(0), "update", "yes", false);
47
        checkArgument((HTTPArgument)arguments.getArgument(0), "update", "yes", "yes", "UTF-8", false);
47
        checkArgument((HTTPArgument)arguments.getArgument(1), "d", "1", false);
48
        checkArgument((HTTPArgument)arguments.getArgument(1), "d", "1", "1", "UTF-8", false);
48
        checkArgument((HTTPArgument)arguments.getArgument(2), "d", "2", false);
49
        checkArgument((HTTPArgument)arguments.getArgument(2), "d", "2", "2", "UTF-8", false);
49
        checkArgument((HTTPArgument)arguments.getArgument(3), "d", "", false);
50
        checkArgument((HTTPArgument)arguments.getArgument(3), "d", "", "", "UTF-8", false);
50
        checkArgument((HTTPArgument)arguments.getArgument(4), "d", "", false);
51
        checkArgument((HTTPArgument)arguments.getArgument(4), "d", "", "", "UTF-8", false);
51
        checkArgument((HTTPArgument)arguments.getArgument(5), "d", "", false);
52
        checkArgument((HTTPArgument)arguments.getArgument(5), "d", "", "", "UTF-8", false);
52
        checkArgument((HTTPArgument)arguments.getArgument(6), "d", "", false);
53
        checkArgument((HTTPArgument)arguments.getArgument(6), "d", "", "", "UTF-8", false);
53
        checkArgument((HTTPArgument)arguments.getArgument(7), "d", "", false);
54
        checkArgument((HTTPArgument)arguments.getArgument(7), "d", "", "", "UTF-8", false);
54
        checkArgument((HTTPArgument)arguments.getArgument(8), "d", "1", false);
55
        checkArgument((HTTPArgument)arguments.getArgument(8), "d", "1", "1", "UTF-8", false);
55
        checkArgument((HTTPArgument)arguments.getArgument(9), "d", "2", false);
56
        checkArgument((HTTPArgument)arguments.getArgument(9), "d", "2", "2", "UTF-8", false);
56
        checkArgument((HTTPArgument)arguments.getArgument(10), "d", "1", false);
57
        checkArgument((HTTPArgument)arguments.getArgument(10), "d", "1", "1", "UTF-8", false);
57
        checkArgument((HTTPArgument)arguments.getArgument(11), "d", "", false);
58
        checkArgument((HTTPArgument)arguments.getArgument(11), "d", "", "", "UTF-8", false);
58
        // I see that the value gets trimmed, not sure if that is correct
59
        checkArgument((HTTPArgument)arguments.getArgument(12), "d", "", "", "UTF-8", false);
59
        checkArgument((HTTPArgument)arguments.getArgument(12), "d", "", false);
60
60
61
        // A HTTP POST request
61
        // A HTTP POST request
62
        String postBody = "update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=&d= ";
62
        String postBody = "update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=&d=";
63
        String TEST_POST_REQ = "POST http://localhost/matrix.html HTTP/1.0\n"
63
        String TEST_POST_REQ = "POST http://localhost/matrix.html HTTP/1.0\n"
64
                + "Content-type: "
64
                + "Content-type: "
65
                + HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED
65
                + HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED
66
                + "; charset=UTF-8\n"
66
                + "; charset=UTF-8\r\n"
67
                + "Content-length: " + postBody.length() + "\r\n"
68
                + "\r\n"
67
                + postBody;
69
                + postBody;
68
        s = getSamplerForRequest(TEST_POST_REQ, "UTF-8");
70
        s = getSamplerForRequest(TEST_POST_REQ, "UTF-8");
69
        assertEquals(HTTPSamplerBase.POST, s.getMethod());
71
        assertEquals(HTTPSamplerBase.POST, s.getMethod());
72
        assertFalse(s.getDoMultipartPost());
70
73
71
        // Check arguments
74
        // Check arguments
72
        arguments = s.getArguments();
75
        arguments = s.getArguments();
73
        assertEquals(13, arguments.getArgumentCount());
76
        assertEquals(13, arguments.getArgumentCount());
74
        checkArgument((HTTPArgument)arguments.getArgument(0), "update", "yes", false);
77
        checkArgument((HTTPArgument)arguments.getArgument(0), "update", "yes", "yes", "UTF-8", false);
75
        checkArgument((HTTPArgument)arguments.getArgument(1), "d", "1", false);
78
        checkArgument((HTTPArgument)arguments.getArgument(1), "d", "1", "1", "UTF-8", false);
76
        checkArgument((HTTPArgument)arguments.getArgument(2), "d", "2", false);
79
        checkArgument((HTTPArgument)arguments.getArgument(2), "d", "2", "2", "UTF-8", false);
77
        checkArgument((HTTPArgument)arguments.getArgument(3), "d", "", false);
80
        checkArgument((HTTPArgument)arguments.getArgument(3), "d", "", "", "UTF-8", false);
78
        checkArgument((HTTPArgument)arguments.getArgument(4), "d", "", false);
81
        checkArgument((HTTPArgument)arguments.getArgument(4), "d", "", "", "UTF-8", false);
79
        checkArgument((HTTPArgument)arguments.getArgument(5), "d", "", false);
82
        checkArgument((HTTPArgument)arguments.getArgument(5), "d", "", "", "UTF-8", false);
80
        checkArgument((HTTPArgument)arguments.getArgument(6), "d", "", false);
83
        checkArgument((HTTPArgument)arguments.getArgument(6), "d", "", "", "UTF-8", false);
81
        checkArgument((HTTPArgument)arguments.getArgument(7), "d", "", false);
84
        checkArgument((HTTPArgument)arguments.getArgument(7), "d", "", "", "UTF-8", false);
82
        checkArgument((HTTPArgument)arguments.getArgument(8), "d", "1", false);
85
        checkArgument((HTTPArgument)arguments.getArgument(8), "d", "1", "1", "UTF-8", false);
83
        checkArgument((HTTPArgument)arguments.getArgument(9), "d", "2", false);
86
        checkArgument((HTTPArgument)arguments.getArgument(9), "d", "2", "2", "UTF-8", false);
84
        checkArgument((HTTPArgument)arguments.getArgument(10), "d", "1", false);
87
        checkArgument((HTTPArgument)arguments.getArgument(10), "d", "1", "1", "UTF-8", false);
85
        checkArgument((HTTPArgument)arguments.getArgument(11), "d", "", false);
88
        checkArgument((HTTPArgument)arguments.getArgument(11), "d", "", "", "UTF-8", false);
86
        checkArgument((HTTPArgument)arguments.getArgument(12), "d", " ", false);
89
        checkArgument((HTTPArgument)arguments.getArgument(12), "d", "", "", "UTF-8", false);
87
90
88
        // A HTTP POST request, with content-type text/plain
91
        // A HTTP POST request, with content-type text/plain
89
        TEST_POST_REQ = "POST http://localhost/matrix.html HTTP/1.0\n"
92
        TEST_POST_REQ = "POST http://localhost/matrix.html HTTP/1.0\n"
Lines 91-102 Link Here
91
                + postBody;
94
                + postBody;
92
        s = getSamplerForRequest(TEST_POST_REQ, "UTF-8");
95
        s = getSamplerForRequest(TEST_POST_REQ, "UTF-8");
93
        assertEquals(HTTPSamplerBase.POST, s.getMethod());
96
        assertEquals(HTTPSamplerBase.POST, s.getMethod());
97
        assertFalse(s.getDoMultipartPost());
94
98
95
        // Check arguments
99
        // Check arguments
96
        // We should have one argument, with the value equal to the post body
100
        // We should have one argument, with the value equal to the post body
97
        arguments = s.getArguments();
101
        arguments = s.getArguments();
98
        assertEquals(1, arguments.getArgumentCount());
102
        assertEquals(1, arguments.getArgumentCount());
99
        checkArgument((HTTPArgument)arguments.getArgument(0), "", postBody, false);
103
        checkArgument((HTTPArgument)arguments.getArgument(0), "", postBody, postBody, "UTF-8", false);
100
    }
104
    }
101
        
105
        
102
    // TODO: will need changing if arguments can be saved in decoded form 
106
    // TODO: will need changing if arguments can be saved in decoded form 
Lines 114-122 Link Here
114
        // Check arguments
118
        // Check arguments
115
        Arguments arguments = s.getArguments();
119
        Arguments arguments = s.getArguments();
116
        assertEquals(3, arguments.getArgumentCount());
120
        assertEquals(3, arguments.getArgumentCount());
117
        checkArgument((HTTPArgument)arguments.getArgument(0), "abc?SPACE", "a+b", false);
121
        checkArgument((HTTPArgument)arguments.getArgument(0), "abc?SPACE", "a+b", "a+b", "UTF-8", false);
118
        checkArgument((HTTPArgument)arguments.getArgument(1), "space", "a%20b", false);
122
        checkArgument((HTTPArgument)arguments.getArgument(1), "space", "a%20b", "a%20b", "UTF-8", false);
119
        checkArgument((HTTPArgument)arguments.getArgument(2), "query", "What?", false);
123
        checkArgument((HTTPArgument)arguments.getArgument(2), "query", "What?", "What?", "UTF-8", false);
120
124
121
        // A HTTP POST request
125
        // A HTTP POST request
122
        String postBody = "abc?SPACE=a+b&space=a%20b&query=What?";
126
        String postBody = "abc?SPACE=a+b&space=a%20b&query=What?";
Lines 127-141 Link Here
127
            + postBody;
131
            + postBody;
128
        s = getSamplerForRequest(TEST_POST_REQ, "UTF-8");
132
        s = getSamplerForRequest(TEST_POST_REQ, "UTF-8");
129
        assertEquals(HTTPSamplerBase.POST, s.getMethod());
133
        assertEquals(HTTPSamplerBase.POST, s.getMethod());
134
        assertFalse(s.getDoMultipartPost());
130
        
135
        
131
        // Check arguments
136
        // Check arguments
132
        arguments = s.getArguments();
137
        arguments = s.getArguments();
133
        assertEquals(3, arguments.getArgumentCount());
138
        assertEquals(3, arguments.getArgumentCount());
134
        checkArgument((HTTPArgument)arguments.getArgument(0), "abc?SPACE", "a+b", false);
139
        checkArgument((HTTPArgument)arguments.getArgument(0), "abc?SPACE", "a+b", "a+b", "UTF-8", false);
135
        checkArgument((HTTPArgument)arguments.getArgument(1), "space", "a%20b", false);
140
        checkArgument((HTTPArgument)arguments.getArgument(1), "space", "a%20b", "a%20b", "UTF-8", false);
136
        checkArgument((HTTPArgument)arguments.getArgument(2), "query", "What?", false);
141
        checkArgument((HTTPArgument)arguments.getArgument(2), "query", "What?", "What?", "UTF-8", false);
137
    }
142
    }
143
    
144
    public void testPostMultipartFormData() throws Exception {
145
        // A HTTP POST request, multipart/form-data, simple values,
146
        String contentEncoding = "UTF-8";
147
        String boundary = "xf8SqlDNvmn6mFYwrioJaeUR2_Z4cLRXOSmB";
148
        String endOfLine = "\r\n";
149
        String titleValue = "mytitle";
150
        String descriptionValue = "mydescription";
151
        String postBody = createMultipartFormBody(titleValue, descriptionValue, contentEncoding, true, boundary, endOfLine);
152
        String testPostRequest = createMultipartFormRequest(postBody, boundary, endOfLine);
138
153
154
        HTTPSamplerBase s = getSamplerForRequest(testPostRequest, "UTF-8");
155
        assertEquals(HTTPSamplerBase.POST, s.getMethod());
156
        assertTrue(s.getDoMultipartPost());
157
        
158
        // Check arguments
159
        Arguments arguments = s.getArguments();
160
        assertEquals(2, arguments.getArgumentCount());
161
        checkArgument((HTTPArgument)arguments.getArgument(0), "title", titleValue, titleValue, contentEncoding, false);
162
        checkArgument((HTTPArgument)arguments.getArgument(1), "description", descriptionValue, descriptionValue, contentEncoding, false);
163
        
164
        // A HTTP POST request, multipart/form-data, simple values,
165
        // with \r\n as end of line, which is according to spec,
166
        // and with more headers in each multipart
167
        endOfLine = "\r\n";
168
        titleValue = "mytitle";
169
        descriptionValue = "mydescription";
170
        postBody = createMultipartFormBody(titleValue, descriptionValue, contentEncoding, true, boundary, endOfLine);
171
        testPostRequest = createMultipartFormRequest(postBody, boundary, endOfLine);
172
173
        s = getSamplerForRequest(testPostRequest, "UTF-8");
174
        assertEquals(HTTPSamplerBase.POST, s.getMethod());
175
        assertTrue(s.getDoMultipartPost());
176
        
177
        // Check arguments
178
        arguments = s.getArguments();
179
        assertEquals(2, arguments.getArgumentCount());
180
        checkArgument((HTTPArgument)arguments.getArgument(0), "title", titleValue, titleValue, contentEncoding, false);
181
        checkArgument((HTTPArgument)arguments.getArgument(1), "description", descriptionValue, descriptionValue, contentEncoding, false);
182
183
        // A HTTP POST request, multipart/form-data, simple values,
184
        // with \n as end of line, which should also be handled,
185
        // and with more headers in each multipart
186
        endOfLine = "\n";
187
        titleValue = "mytitle";
188
        descriptionValue = "mydescription";
189
        postBody = createMultipartFormBody(titleValue, descriptionValue, contentEncoding, true, boundary, endOfLine);
190
        testPostRequest = createMultipartFormRequest(postBody, boundary, endOfLine);
191
192
        s = getSamplerForRequest(testPostRequest, "UTF-8");
193
        assertEquals(HTTPSamplerBase.POST, s.getMethod());
194
        assertTrue(s.getDoMultipartPost());
195
        
196
        // Check arguments
197
        arguments = s.getArguments();
198
        assertEquals(2, arguments.getArgumentCount());
199
        checkArgument((HTTPArgument)arguments.getArgument(0), "title", titleValue, titleValue, contentEncoding, false);
200
        checkArgument((HTTPArgument)arguments.getArgument(1), "description", descriptionValue, descriptionValue, contentEncoding, false);
201
        
202
        // A HTTP POST request, multipart/form-data, with value that will change
203
        // if they are url encoded
204
        // Values are similar to __VIEWSTATE parameter that .net uses
205
        endOfLine = "\r\n";
206
        titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc=";
207
        descriptionValue = "mydescription";
208
        postBody = createMultipartFormBody(titleValue, descriptionValue, contentEncoding, true, boundary, endOfLine);
209
        testPostRequest = createMultipartFormRequest(postBody, boundary, endOfLine);
210
211
        s = getSamplerForRequest(testPostRequest, "UTF-8");
212
        assertEquals(HTTPSamplerBase.POST, s.getMethod());
213
        assertTrue(s.getDoMultipartPost());
214
        
215
        // Check arguments
216
        arguments = s.getArguments();
217
        assertEquals(2, arguments.getArgumentCount());
218
        checkArgument((HTTPArgument)arguments.getArgument(0), "title", titleValue, titleValue, contentEncoding, false);
219
        checkArgument((HTTPArgument)arguments.getArgument(1), "description", descriptionValue, descriptionValue, contentEncoding, false);
220
    }
221
222
    public void testPostMultipartFileUpload() throws Exception {
223
        // A HTTP POST request, multipart/form-data, simple values,
224
        String boundary = "xf8SqlDNvmn6mFYwrioJaeUR2_Z4cLRXOSmB";
225
        String endOfLine = "\r\n";
226
        String fileFieldValue = "test_file";
227
        String fileName = "somefilename.txt";
228
        String mimeType = "text/plain";
229
        String fileContent = "somedummycontent\n\ndfgdfg\r\nfgdgdg\nContent-type:dfsfsfds";
230
        String postBody = createMultipartFileUploadBody(fileFieldValue, fileName, mimeType, fileContent, boundary, endOfLine);
231
        String testPostRequest = createMultipartFormRequest(postBody, boundary, endOfLine);
232
        
233
        HTTPSamplerBase s = getSamplerForRequest(testPostRequest, "UTF-8");
234
        assertEquals(HTTPSamplerBase.POST, s.getMethod());
235
        assertTrue(s.getDoMultipartPost());
236
237
        // Check arguments
238
        Arguments arguments = s.getArguments();
239
        assertEquals(0, arguments.getArgumentCount());
240
        assertEquals(fileFieldValue, s.getFileField());
241
        assertEquals(fileName, s.getFilename());
242
        assertEquals(mimeType, s.getMimetype());
243
    }        
244
    
245
    private String createMultipartFormBody(String titleValue, String descriptionValue, String contentEncoding, boolean includeExtraHeaders, String boundary, String endOfLine) {
246
        // Title multipart
247
        String postBody = "--" + boundary + endOfLine
248
            + "Content-Disposition: form-data; name=\"title\"" + endOfLine;
249
        if(includeExtraHeaders) {
250
            postBody += "Content-Type: text/plain; charset=" + contentEncoding + endOfLine
251
            + "Content-Transfer-Encoding: 8bit" + endOfLine;
252
        }
253
        postBody += endOfLine
254
            + titleValue + endOfLine
255
            + "--" + boundary + endOfLine;
256
        // Description multipart
257
        postBody += "Content-Disposition: form-data; name=\"description\"" + endOfLine;
258
        if(includeExtraHeaders) {
259
            postBody += "Content-Type: text/plain; charset=" + contentEncoding + endOfLine
260
                + "Content-Transfer-Encoding: 8bit" + endOfLine;
261
        }
262
        postBody += endOfLine
263
            + descriptionValue + endOfLine
264
            + "--" + boundary + "--" + endOfLine;
265
266
        return postBody;
267
    }
268
269
    private String createMultipartFileUploadBody(String fileField, String fileName, String fileMimeType, String fileContent, String boundary, String endOfLine) {
270
        // File upload multipart
271
        String postBody = "--" + boundary + endOfLine
272
            + "Content-Disposition: form-data; name=\"" + fileField + "\" filename=\"" + fileName + "\"" + endOfLine
273
            + "Content-Type: " + fileMimeType + endOfLine
274
            + "Content-Transfer-Encoding: binary" + endOfLine
275
            + endOfLine
276
            + fileContent + endOfLine
277
            + "--" + boundary + "--" + endOfLine;
278
        return postBody;
279
    }
280
    
281
    private String createMultipartFormRequest(String postBody, String boundary, String endOfLine) {
282
        String postRequest = "POST http://localhost:80/matrix.html HTTP/1.1" + endOfLine
283
            + "Content-type: "
284
            + HTTPSamplerBase.MULTIPART_FORM_DATA
285
            + "; boundary=" + boundary + endOfLine
286
            + "Content-length: " + postBody.length() + endOfLine
287
            + endOfLine
288
            + postBody;
289
        return postRequest;
290
    }
291
139
    private HTTPSamplerBase getSamplerForRequest(String request, String contentEncoding)
292
    private HTTPSamplerBase getSamplerForRequest(String request, String contentEncoding)
140
            throws IOException {
293
            throws IOException {
141
        HttpRequestHdr req = new HttpRequestHdr();
294
        HttpRequestHdr req = new HttpRequestHdr();
Lines 149-157 Link Here
149
            HTTPArgument arg,
302
            HTTPArgument arg,
150
            String expectedName,
303
            String expectedName,
151
            String expectedValue,
304
            String expectedValue,
152
            boolean expectedEncoded) {
305
            String expectedEncodedValue,
306
            String contentEncoding,
307
            boolean expectedEncoded) throws IOException {
153
        assertEquals(expectedName, arg.getName());
308
        assertEquals(expectedName, arg.getName());
154
        assertEquals(expectedValue, arg.getValue());
309
        assertEquals(expectedValue, arg.getValue());
310
        assertEquals(expectedEncodedValue, arg.getEncodedValue(contentEncoding));
155
        assertEquals(expectedEncoded, arg.isAlwaysEncoded());
311
        assertEquals(expectedEncoded, arg.isAlwaysEncoded());
156
    }
312
    }
157
}
313
}
(-)C:/Documents and Settings/alf.hogemark/workspace/JMeter 2.2 official_2/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java (+16 lines)
Lines 208-213 Link Here
208
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
208
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
209
        res = executeSampler(sampler);
209
        res = executeSampler(sampler);
210
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
210
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
211
        
212
        // Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses,
213
        // with values urlencoded, but the always encode set to false for the arguments
214
        // This is how the HTTP Proxy server adds arguments to the sampler
215
        sampler = createHttpSampler(samplerType);
216
        contentEncoding = "UTF-8";
217
        titleValue = "%2FwEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ%2FrA%2B8DZ2dnZ2dnZ2d%2FGNDar6OshPwdJc%3D";
218
        descriptionValue = "mydescription";
219
        setupUrl(sampler, contentEncoding);
220
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
221
        ((HTTPArgument)sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
222
        ((HTTPArgument)sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
223
        res = executeSampler(sampler);
224
        assertFalse(((HTTPArgument)sampler.getArguments().getArgument(0)).isAlwaysEncoded());
225
        assertFalse(((HTTPArgument)sampler.getArguments().getArgument(1)).isAlwaysEncoded());
226
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, true);
211
227
212
        // Test sending data as UTF-8, where user defined variables are used
228
        // Test sending data as UTF-8, where user defined variables are used
213
        // to set the value for form data
229
        // to set the value for form data
(-)C:/Documents and Settings/alf.hogemark/workspace/JMeter 2.2 official_2/src/protocol/http/org/apache/jmeter/protocol/http/config/MultipartUrlConfig.java (-18 / +71 lines)
Lines 22-28 Link Here
22
22
23
import org.apache.jmeter.config.Arguments;
23
import org.apache.jmeter.config.Arguments;
24
import org.apache.jmeter.protocol.http.util.HTTPArgument;
24
import org.apache.jmeter.protocol.http.util.HTTPArgument;
25
import org.apache.jmeter.util.JMeterUtils;
25
import org.apache.jorphan.util.JOrphanUtils;
26
import org.apache.jorphan.util.JOrphanUtils;
27
import org.apache.oro.text.regex.Pattern;
28
import org.apache.oro.text.regex.Perl5Compiler;
29
import org.apache.oro.text.regex.Perl5Matcher;
26
30
27
/**
31
/**
28
 * @author Michael Stover
32
 * @author Michael Stover
Lines 92-97 Link Here
92
		myArgs.addArgument(new HTTPArgument(name, value, metadata));
96
		myArgs.addArgument(new HTTPArgument(name, value, metadata));
93
	}
97
	}
94
98
99
    /**
100
     * @deprecated values in a multipart/form-data are not urlencoded,
101
     * so it does not make sense to add a value as a encoded value
102
     */
95
	public void addEncodedArgument(String name, String value) {
103
	public void addEncodedArgument(String name, String value) {
96
		Arguments myArgs = getArguments();
104
		Arguments myArgs = getArguments();
97
		HTTPArgument arg = new HTTPArgument(name, value, true);
105
		HTTPArgument arg = new HTTPArgument(name, value, true);
Lines 100-105 Link Here
100
		}
108
		}
101
		myArgs.addArgument(arg);
109
		myArgs.addArgument(arg);
102
	}
110
	}
111
    
112
    /**
113
     * Add a value that is not URL encoded, and make sure it
114
     * appears in the GUI that it will not be encoded when
115
     * the request is sent.
116
     * 
117
     * @param name
118
     * @param value
119
     */
120
    private void addNonEncodedArgument(String name, String value) {
121
        Arguments myArgs = getArguments();
122
        // The value is not encoded
123
        HTTPArgument arg = new HTTPArgument(name, value, false);
124
        // Let the GUI show that it will not be encoded
125
        arg.setAlwaysEncoded(false);
126
        myArgs.addArgument(arg);
127
    }
103
128
104
	/**
129
	/**
105
	 * This method allows a proxy server to send over the raw text from a
130
	 * This method allows a proxy server to send over the raw text from a
Lines 109-132 Link Here
109
	public void parseArguments(String queryString) {
134
	public void parseArguments(String queryString) {
110
		String[] parts = JOrphanUtils.split(queryString, "--" + getBoundary());
135
		String[] parts = JOrphanUtils.split(queryString, "--" + getBoundary());
111
		for (int i = 0; i < parts.length; i++) {
136
		for (int i = 0; i < parts.length; i++) {
112
			if (parts[i].indexOf("filename=") > -1) {
137
            String contentDisposition = getHeaderValue("Content-disposition", parts[i]);
113
				int index = parts[i].indexOf("name=\"") + 6;
138
            String contentType = getHeaderValue("Content-type", parts[i]);
114
				String name = parts[i].substring(index, parts[i].indexOf("\"", index));
139
            // Check if it is form data
115
				index = parts[i].indexOf("filename=\"") + 10;
140
            if (contentDisposition != null && contentDisposition.indexOf("form-data") > -1) {
116
				String fn = parts[i].substring(index, parts[i].indexOf("\"", index));
141
                // Get the form field name
117
				index = parts[i].indexOf("\n", index);
142
                int index = contentDisposition.indexOf("name=\"") + 6;
118
				index = parts[i].indexOf(":", index) + 1;
143
                String name = contentDisposition.substring(index, contentDisposition.indexOf("\"", index));
119
				String mt = parts[i].substring(index, parts[i].indexOf("\n", index)).trim();
144
120
				this.setFileFieldName(name);
145
                // Check if it is a file being uploaded
121
				this.setFilename(fn);
146
                if (contentDisposition.indexOf("filename=") > -1) {
122
				this.setMimeType(mt);
147
                    // Get the filename
123
			} else if (parts[i].indexOf("name=") > -1) {
148
                    index = contentDisposition.indexOf("filename=\"") + 10;
124
				int index = parts[i].indexOf("name=\"") + 6;
149
                    String fn = contentDisposition.substring(index, contentDisposition.indexOf("\"", index));
125
				String name = parts[i].substring(index, parts[i].indexOf("\"", index));
150
                    if(fn != null && fn.length() > 0) {
126
				index = parts[i].indexOf("\n", index) + 2;
151
                        // Set the values retrieves for the file upload
127
				String value = parts[i].substring(index).trim();
152
                        this.setFileFieldName(name);
128
				this.addArgument(name, value);
153
                        this.setFilename(fn);
129
			}
154
                        this.setMimeType(contentType);
155
                    }
156
                }
157
                else {
158
                    // Find the first empty line of the multipart, it signals end of headers for multipart
159
                    int indexEmptyLfCrLfLinePos = parts[i].indexOf("\n\r\n");
160
                    int indexEmptyLfLfLinePos = parts[i].indexOf("\n\n");
161
                    String value = null;
162
                    if(indexEmptyLfCrLfLinePos > -1) {
163
                        value = parts[i].substring(indexEmptyLfCrLfLinePos).trim();
164
                    }
165
                    else if(indexEmptyLfLfLinePos > -1) {
166
                        value = parts[i].substring(indexEmptyLfLfLinePos).trim();
167
                    }
168
                    this.addNonEncodedArgument(name, value);
169
                }
170
            }
130
		}
171
		}
131
	}
172
	}
173
    
174
    private String getHeaderValue(String headerName, String multiPart) {
175
        String regularExpression = headerName + "\\s*:\\s*(.*)$";
176
        Perl5Matcher localMatcher = JMeterUtils.getMatcher();
177
        Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
178
        if(localMatcher.contains(multiPart, pattern)) {
179
            return localMatcher.getMatch().group(1).trim();
180
        }
181
        else {
182
            return null;
183
        }
184
    }
132
}
185
}

Return to bug 42158