Skip to content

Commit

Permalink
HTTPCORE-742: BasicHttpRequest#setUri does not correctly reset intern…
Browse files Browse the repository at this point in the history
…al state
  • Loading branch information
ok2c committed Apr 27, 2023
1 parent 946f8b3 commit 7376337
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

package org.apache.hc.core5.http.message;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.Method;
Expand All @@ -36,9 +39,6 @@
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.TextUtils;

import java.net.URI;
import java.net.URISyntaxException;

/**
* Basic implementation of {@link HttpRequest}.
*
Expand Down Expand Up @@ -288,6 +288,7 @@ public void setUri(final URI requestUri) {
buf.append('?').append(query);
}
this.path = buf.toString();
this.requestUri = null;
}

private void assembleRequestUri(final StringBuilder buf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.Method;
import org.apache.hc.core5.net.URIAuthority;
import org.apache.hc.core5.net.URIBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -211,5 +212,18 @@ public void testRequestAbsoluteRequestUri() throws Exception {
Assertions.assertEquals("http://somehost/stuff", request.getRequestUri());
}

@Test
public void testModifyingExistingRequest() throws Exception {
final URI uri = URI.create("https://example.org");
final HttpRequest request = new BasicHttpRequest(Method.GET, uri);

final URI newUri = new URIBuilder(request.getUri())
.addParameter("name", "value")
.build();

request.setUri(newUri);
Assertions.assertEquals(newUri, request.getUri());
}

}

0 comments on commit 7376337

Please sign in to comment.