jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felix Schumacher <felix.schumac...@internetallee.de>
Subject Re: [jmeter] branch master updated: Better parse curl commands with backslash at line endings and support PUT method with data arguments
Date Sun, 02 Aug 2020 07:34:13 GMT


Am 1. August 2020 22:58:35 MESZ schrieb Philippe Mouawad <philippe.mouawad@gmail.com>:
>Hello Felix,
>Sorry for noticing this a bit late.
>See my remark inline below.
>
>Maybe I misunderstand the fix.
>
>Thanks
>Regards
>
>On Tue, Jun 9, 2020 at 12:50 PM <fschumacher@apache.org> wrote:
>
>> This is an automated email from the ASF dual-hosted git repository.
>>
>> fschumacher pushed a commit to branch master
>> in repository https://gitbox.apache.org/repos/asf/jmeter.git
>>
>>
>> The following commit(s) were added to refs/heads/master by this push:
>>      new 353ad79  Better parse curl commands with backslash at line
>> endings and support PUT method with data arguments
>> 353ad79 is described below
>>
>> commit 353ad79c5497c4d624f8b276580b6b50d45b27b9
>> Author: Felix Schumacher <felix.schumacher@internetallee.de>
>> AuthorDate: Tue Jun 9 12:49:00 2020 +0200
>>
>>     Better parse curl commands with backslash at line endings and
>support
>> PUT method with data arguments
>>
>>     Bugzilla Id: 64446
>> ---
>>  .../jmeter/protocol/http/curl/BasicCurlParser.java    |  6 ++++--
>>  .../org/apache/jmeter/curl/BasicCurlParserTest.java   | 19
>> +++++++++++++++++++
>>  xdocs/changes.xml                                     |  1 +
>>  3 files changed, 24 insertions(+), 2 deletions(-)
>>
>> diff --git
>>
>a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
>>
>b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
>> index 0c7fcd6..8d95da2 100644
>> ---
>>
>a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
>> +++
>>
>b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
>> @@ -700,7 +700,9 @@ public class BasicCurlParser {
>>                      String value = option.getArgument(0);
>>                      String dataOptionName =
>> option.getDescriptor().getName();
>>                      value =
>getPostDataByDifferentOption(value.trim(),
>> dataOptionName);
>> -                    request.setMethod("POST");
>> +                    if ("GET".equals(request.getMethod())) {
>> +                        request.setMethod("POST");
>> +                    }
>>
>Isn't it weird to transform a GET into a POST ?
>Get with body data is possible in JMeter

GET is the hard-coded default method. If the user doesn't set a method GET is returned. That
means, we can't decide whether it is the default or explicitly chosen. On the other hand side,
before we set the method to POST even if user chose a method explicitly. 

So I think we are doing now a bit better in giving the user what was wanted. 

To make the GET case work in all circumstance we would have to change the return value and
that would cascade into quite a lot of places. 

Regards 
Felix 

>
>                     request.setPostData(value);
>>                  } else if
>> (FORMS_OPT.contains(option.getDescriptor().getId())) {
>>                      String nameAndValue = option.getArgument(0);
>> @@ -850,7 +852,7 @@ public class BasicCurlParser {
>>                          current.setLength(0);
>>                      }
>>                  } else {
>> -                    current.append(nextTok);
>> +                   
>current.append(nextTok.replaceAll("^\\\\[\\r\\n]",
>> ""));
>>                  }
>>                  lastTokenHasBeenQuoted = false;
>>                  break;
>> diff --git
>>
>a/src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java
>>
>b/src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java
>> index 39f003b..c9f9228 100644
>> ---
>>
>a/src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java
>> +++
>>
>b/src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java
>> @@ -89,6 +89,25 @@ public class BasicCurlParserTest {
>>      }
>>
>>      @Test
>> +    public void testBackslashAtLineEnding() {
>> +        String cmdLine = "curl \\\n-d 'hey'
>http://jmeter.apache.org/";
>> +        BasicCurlParser basicCurlParser = new BasicCurlParser();
>> +        BasicCurlParser.Request request =
>basicCurlParser.parse(cmdLine);
>> +        assertEquals("http://jmeter.apache.org/", request.getUrl());
>> +        assertEquals("hey", request.getPostData());
>> +    }
>> +
>> +    @Test
>> +    public void testSetRequestMethodOnData() {
>> +        String cmdLine = "curl -X PUT -d 'hey'
>http://jmeter.apache.org/
>> ";
>> +        BasicCurlParser basicCurlParser = new BasicCurlParser();
>> +        BasicCurlParser.Request request =
>basicCurlParser.parse(cmdLine);
>> +        assertEquals("http://jmeter.apache.org/", request.getUrl());
>> +        assertEquals("hey", request.getPostData());
>> +        assertEquals("PUT", request.getMethod());
>> +    }
>> +
>> +    @Test
>>      public void testChromeParsingNotCompressed() {
>>          String cmdLine = "curl 'https://jmeter.apache.org/' -H
>> 'Proxy-Connection: keep-alive' "
>>                  + "-H 'Proxy-Authorization: Basic XXXXXXXXX/' -H
>> 'Upgrade-Insecure-Requests: 1' "
>> diff --git a/xdocs/changes.xml b/xdocs/changes.xml
>> index f2c8db3..0772b9a 100644
>> --- a/xdocs/changes.xml
>> +++ b/xdocs/changes.xml
>> @@ -109,6 +109,7 @@ Summary
>>
>>  <h3>General</h3>
>>  <ul>
>> +  <li><bug>64446</bug>Better parse curl commands with backslash
at
>line
>> endings and support <code>PUT</code> method with data arguments</li>
>>  </ul>
>>
>>  <ch_section>Non-functional changes</ch_section>
>>
>>

Mime
View raw message