matrei commented on code in PR #15478:
URL: https://github.com/apache/grails-core/pull/15478#discussion_r2890716950


##########
grails-test-examples/app1/src/integration-test/groovy/functionaltests/flow/FlashChainForwardSpec.groovy:
##########
@@ -40,95 +38,69 @@ import grails.testing.mixin.integration.Integration
  * flash scope and chain model which rely on HTTP session state.
  */
 @Integration
-class FlashChainForwardSpec extends Specification {
-
-    @Shared
-    HttpClient client
+class FlashChainForwardSpec extends Specification implements HttpClientSupport 
{
 
     @Shared
-    HttpClient noRedirectClient
-
-    def setup() {
-        client = client ?: HttpClient.create(new 
URL("http://localhost:$serverPort";))
-        if (!noRedirectClient) {
-            def config = new DefaultHttpClientConfiguration()
-            config.setFollowRedirects(false)
-            noRedirectClient = HttpClient.create(new 
URL("http://localhost:$serverPort";), config)
-        }
-    }
-
-    def cleanupSpec() {
-        client?.close()
-        noRedirectClient?.close()
-    }
-
-    /**
-     * Helper to extract session cookie from Set-Cookie header.
-     */
-    private String extractSessionCookie(String setCookieHeader) {
-        if (!setCookieHeader) return null
-        setCookieHeader.split(';')[0]
+    HttpClient noRedirectClient = httpClientWith {
+        followRedirects(HttpClient.Redirect.NEVER)
     }
 
     /**
      * Helper to follow redirect manually with session cookie.
      */
-    private Map followRedirectWithSession(String path) {
+    private HttpResponse<String> followRedirectWithSession(String path) {
         // First request - get redirect and session cookie
-        def response1 = noRedirectClient.toBlocking().exchange(
-            HttpRequest.GET(path),
-            String
-        )
+        def response1 = http(path, noRedirectClient)
         
-        def sessionCookie = 
extractSessionCookie(response1.header('Set-Cookie'))
-        def location = response1.header('Location')
+        def sessionCookie = response1.headerValue('Set-Cookie')
+        def location = response1.headerValue('Location')
         
         if (!location) {
             // Not a redirect, parse body
-            return new JsonSlurper().parseText(response1.body())
+            return response1
         }
         
         // Follow redirect with session cookie
         def redirectPath = location.startsWith('http') ? 
-            new URL(location).path + (new URL(location).query ? "?${new 
URL(location).query}" : '') : 
-            location
+                new URL(location).path + (new URL(location).query ? "?${new 
URL(location).query}" : '') :
+                location
         
-        def request2 = HttpRequest.GET(redirectPath)
+        def headers = [:] as Map<String, String>
         if (sessionCookie) {
-            request2 = request2.header('Cookie', sessionCookie)
+            headers.put('Cookie', sessionCookie)
         }

Review Comment:
   It's good enough for this test 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]

Reply via email to