wleeaf commented on code in PR #904:
URL: 
https://github.com/apache/httpcomponents-client/pull/904#discussion_r4376733708


##########
httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultRedirectStrategy.java:
##########
@@ -163,6 +163,28 @@ void testGetLocationUriRelative() throws Exception {
         Assertions.assertEquals(URI.create("http://localhost/stuff";), uri);
     }
 
+    @Test
+    void testGetLocationUriRelativeQueryOnly() throws Exception {
+        final DefaultRedirectStrategy redirectStrategy = new 
DefaultRedirectStrategy();
+        final HttpClientContext context = HttpClientContext.create();
+        final HttpGet httpget = new 
HttpGet("http://localhost/stuff/index.html?a=1";);
+        final HttpResponse response = new 
BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
+        response.addHeader("Location", "?b=2");
+        final URI uri = redirectStrategy.getLocationURI(httpget, response, 
context);
+        
Assertions.assertEquals(URI.create("http://localhost/stuff/index.html?b=2";), 
uri);
+    }
+
+    @Test
+    void testGetLocationUriFragmentOnly() throws Exception {
+        final DefaultRedirectStrategy redirectStrategy = new 
DefaultRedirectStrategy();
+        final HttpClientContext context = HttpClientContext.create();
+        final HttpGet httpget = new 
HttpGet("http://localhost/stuff/index.html?a=1";);
+        final HttpResponse response = new 
BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
+        response.addHeader("Location", "#fragment");

Review Comment:
   Right, the fragment isn't sent. What the fragment-only case checks is the 
rest of the target: with `Location: #fragment`, the request goes to 
`/stuff/index.html?a=1`, the current resource (RFC 3986 5.2.2 keeps the base 
path and query), instead of `/`. I can drop that test and keep only the `?b=2` 
one if you'd rather not have a fragment-only case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to