14
14
//
15
15
16
16
using System . Net ;
17
+ using RestSharp . Extensions ;
17
18
using RestSharp . Tests . Integrated . Server ;
18
19
19
20
namespace RestSharp . Tests . Integrated ;
@@ -99,6 +100,30 @@ public async Task Can_Perform_PUT_Async_With_RedirectionResponse_Cookies() {
99
100
response . StatusCode . Should ( ) . Be ( HttpStatusCode . MethodNotAllowed ) ;
100
101
}
101
102
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
+
102
127
// Needed tests:
103
128
//Test: ForwardHeaders = false
104
129
//Test: ForwardHeaders = true (default) might not need separate test
@@ -112,7 +137,7 @@ public async Task Can_Perform_PUT_Async_With_RedirectionResponse_Cookies() {
112
137
//Test: ForwardQuery = true (default, might not need test)
113
138
//Test: ForwardQuery = false
114
139
//Test: MaxRedirects
115
- //Test: ForwardFragment = true
140
+ //Test: ForwardFragment = true (default)
116
141
//Test: ForwardFragment = false
117
142
//Test: AllowRedirectMethodStatusCodeToAlterVerb = true (default, might not need test)
118
143
//Test: AllowRedirectMethodStatusCodeToAlterVerb = false
0 commit comments