sahaya / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

rest assured looses cookies are between requests #236

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am using rest assured for multiple requests. It looks like cookies are lost, 
even when the underlying httpclient is configured to accept cookies.
Is a new instance created for each request? (If so, that should really be 
configurable)

@Test
    public void shouldKeepCookies()
    {
        RestAssured.reset();
        RestAssured.config = RestAssuredConfig.config().httpClient( new HttpClientConfig().setParam(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH));

        given().expect().statusCode(200).when().get("fancyInit"); //cookies are set here
        given().body("{}").expect().statusCode(200).when().post("process"); //no cookies are sent here
    }

Original issue reported on code.google.com by everf...@gmail.com on 11 May 2013 at 6:25

GoogleCodeExporter commented 9 years ago
Yes a new client is created for each request. It would be nice to make this 
configurable. Please help out!

Original comment by johan.ha...@gmail.com on 14 May 2013 at 6:57

GoogleCodeExporter commented 9 years ago
The underlying http client is reinstantiated for each request. But it's now 
possible to configure this by providing your own http client factory, for 
example:

 given().
                config(newConfig().httpClient(HttpClientConfig.httpClientConfig().httpClientFactory(new HttpClientConfig.HttpClientFactory() {

                    @Override
                    public AbstractHttpClient createHttpClient() throws Exception {
                        return new SystemDefaultHttpClient();
                    }
                }))).

Instead of returning a new "SystemDefaultHttpClient" you can make sure that the 
same instance is reused. Please try this out by depending on version 
1.8.2-SNAPSHOT after having added the following maven repo:

<repositories>
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <snapshots />
        </repository>
</repositories>

Original comment by johan.ha...@gmail.com on 13 Nov 2013 at 7:06

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 19 Nov 2013 at 6:42