1414//
1515
1616using System . Net ;
17+ using RestSharp . Extensions ;
1718using RestSharp . Tests . Integrated . Server ;
1819
1920namespace RestSharp . Tests . Integrated ;
@@ -99,6 +100,30 @@ public async Task Can_Perform_PUT_Async_With_RedirectionResponse_Cookies() {
99100 response . StatusCode . Should ( ) . Be ( HttpStatusCode . MethodNotAllowed ) ;
100101 }
101102
103+ [ Fact ]
104+ public async Task Can_ForwardHeadersTrue_OnRedirect ( ) {
105+ // This request sets cookies and redirects to url param value
106+ // if supplied, otherwise redirects to /get-cookies
107+ var request = new RestRequest ( "/get-cookies-redirect" ) {
108+ Method = Method . Get ,
109+ } ;
110+ request . AddQueryParameter ( "url" , "/dump-headers" ) ;
111+
112+ var response = await _client . ExecuteAsync ( request ) ;
113+ response . ResponseUri . Should ( ) . Be ( $ "{ _client . Options . BaseUrl } dump-headers") ;
114+ var content = response . Content ;
115+ content . Should ( ) . Contain ( "'Accept':" ) ;
116+ content . Should ( ) . Contain ( $ "'Host': { _client . Options . BaseHost } ") ;
117+ content . Should ( ) . Contain ( "'User-Agent':" ) ;
118+ content . Should ( ) . Contain ( "'Accept-Encoding':" ) ;
119+ content . Should ( ) . Contain ( "'Cookie':" ) ;
120+
121+ // Verify the cookie exists from the redirected get:
122+ response . Cookies . Count . Should ( ) . BeGreaterThan ( 0 ) . And . Be ( 1 ) ;
123+ response . Cookies [ 0 ] . Name . Should ( ) . Be ( "redirectCookie" ) ;
124+ response . Cookies [ 0 ] . Value . Should ( ) . Be ( "value1" ) ;
125+ }
126+
102127 // Needed tests:
103128 //Test: ForwardHeaders = false
104129 //Test: ForwardHeaders = true (default) might not need separate test
@@ -112,7 +137,7 @@ public async Task Can_Perform_PUT_Async_With_RedirectionResponse_Cookies() {
112137 //Test: ForwardQuery = true (default, might not need test)
113138 //Test: ForwardQuery = false
114139 //Test: MaxRedirects
115- //Test: ForwardFragment = true
140+ //Test: ForwardFragment = true (default)
116141 //Test: ForwardFragment = false
117142 //Test: AllowRedirectMethodStatusCodeToAlterVerb = true (default, might not need test)
118143 //Test: AllowRedirectMethodStatusCodeToAlterVerb = false
0 commit comments