Github user squarebracket commented on the issue:
https://github.com/apache/jmeter/pull/261
That's a fair point, but I'm not sure what to do with what you said.
Consider the following situation which occurs in the current code:
```java
sampler.setPath("/index.html?p1=p2");
sampler.sample(); // called for index.html?p1=p2
sampler.setPath("/index.html?p3=p4");
sampler.sample(); // called for index.html?p1=p2&p3=p4
```
Should this be the case? Should query parameters accumulate? If the answer
is yes, that is fine; I will close this PR and implement a fix in my class
which inherites from `HTTPSamplerBase`. However, that should probably be
documented since I certainly was not expecting such behaviour.
If the answer is no, then the question is where the fix should be
implemented. An obvious place would be at the end of `sample()` -- the logical
end of the request -- but it can't be implemented there since it's an abstract
method. Of course, even if you did that, you might end up with something like
this, which I consider unexpected:
```java
sampler.setPath("/index.html?p1=p2");
sampler.sample(); // called for index.html?p1=p2
sampler.sample(); // called for index.html
```
My thought was that changing the path is logically associated with changing
the query string. You're on a different URL so keeping the same query string is
_probably_ not what you want. The simple fix that I implemented simply clears
the query string when `setPath` is called so that this works as expected:
```java
sampler.setPath("/index.html?p1=p2");
sampler.addArgument("p3", "p4");
sampler.sample(); // called for index.html?p1=p2&p3=p4
```
But this does not, since `setPath` is called in between:
```java
sampler.addArgument("p3", "p4");
sampler.setPath("/index.html?p1=p2");
sampler.sample(); // called for index.html?p1=p2
```
I can simply add an `if` statement which wouldn't clear the query string if
the path is `""`, so that this would work, and all currently-existing tests
would pass without modification:
```java
sampler.addArgument("p3", "p4");
sampler.setPath("/index.html?p1=p2");
sampler.sample(); // called for index.html?p1=p2&p3=p4
```
But this would still cause unexpected behaviour like so:
```
sampler.addArgument("p3", "p4");
sampler.setPath("/index.html?p1=p2");
sampler.sample(); // called for index.html?p1=p2&p3=p4
sampler.addArgument("p5", "p6");
sampler.setPath("/index.html?p7=p8");
sampler.sample(); // called for index.html?p7=p8
```
Let me know what you think.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---