New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements in processing redirects with cookie containers. #2119
Draft
rassilon
wants to merge
24
commits into
restsharp:dev
Choose a base branch
from
rassilon:follow-redirects
base: dev
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
164b45f
WIP
alexeyzimarev c6b39b5
Improvements in processing redirects with cookie containers.
rassilon 00b718e
Added very first of many redirection cookie tests.
rassilon 30eab16
Added very first of many redirection cookie tests.
rassilon 9c56c06
Update previous redirect test case since, the redirected URL sends co…
rassilon 1f9a142
Additional tests
rassilon d39f15c
more redirection/cookie related routes
rassilon 653d0e0
Fix build error with respect to System.Web.HttpUtility.ParseQueryStri…
rassilon 487f138
Add new files..
rassilon a0baaa6
FileParameter: Mark the obsoleted property as NOT CLSCompliant to red…
rassilon d3c7806
Try to pull in the correct assemblies for System.Web.HttpUtility.Pars…
rassilon 28203df
Start paying attention to some of the Options.RedirectionOptions pro…
rassilon 6557da7
Fix coding style violation..
rassilon eaae0b1
Improvements (and corrections on some tiny merge errors during) based…
rassilon 9d8baf5
Fixes for Interceptor tests.
rassilon 6764396
Start the process of testing the new RedirectOptions..
rassilon a69b48e
Update xunit adapter and visual studio test SDK nuget pkg versions fo…
rassilon 88d141b
ForwardHeaders/ForwardAuthorization/ForwardCookies tests..
rassilon 73df366
Add RedirectOptions.ForwardQuery support and tests.
rassilon aecb8bb
Fix Fragment handling with AddQueryString extension, and add ForwardF…
rassilon 7b969f5
Add RedirectOptions.MaxRedirects support and tests.
rassilon 950be06
Add secure test server end point to TestServer.
rassilon ee5e151
minor tweaks
rassilon 4ca3453
RestClient.Async.cs: Convert lots of bools to a [Flag] enum setup.
rassilon File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
using RestSharp.Extensions; | ||
using System.Net; | ||
using System.Reflection; | ||
|
||
namespace RestSharp; | ||
|
||
/// <summary> | ||
/// Options related to redirect processing. | ||
/// </summary> | ||
[GenerateImmutable] | ||
public class RestClientRedirectionOptions { | ||
static readonly Version Version = new AssemblyName(typeof(RestClientOptions).Assembly.FullName!).Version!; | ||
|
||
/// <summary> | ||
/// Set to true (default), when you want to follow redirects | ||
/// </summary> | ||
public bool FollowRedirects { get; set; } = true; | ||
|
||
/// <summary> | ||
/// Set to true (default is false), when you want to follow a | ||
/// redirect from HTTPS to HTTP. | ||
/// </summary> | ||
public bool FollowRedirectsToInsecure { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Set to true (default), when you want to include the originally | ||
/// requested headers in redirected requests. | ||
/// </summary> | ||
/// <remarks>NOTE: The 'Authorization' header is controlled by <see cref="ForwardAuthorization"/>, | ||
/// and the 'Cookie' header is controlled by <see cref="ForwardCookies"/>. | ||
/// </remarks> | ||
public bool ForwardHeaders { get; set; } = true; | ||
|
||
/// <summary> | ||
/// Set to true (default is false), when you want to send the original | ||
/// Authorization header to the redirected destination. | ||
/// </summary> | ||
public bool ForwardAuthorization { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Set to true (default), when you want to include cookies from the | ||
/// <see cref="CookieContainer"/> on the redirected URL. | ||
/// </summary> | ||
/// <remarks> | ||
/// NOTE: The exact cookies sent to the redirected url DEPENDS directly | ||
/// on the redirected url. A redirection to a completly differnet FQDN | ||
/// for example is unlikely to actually propagate any cookies from the | ||
/// <see cref="CookieContainer"/>. | ||
/// </remarks> | ||
public bool ForwardCookies { get; set; } = true; | ||
|
||
/// <summary> | ||
/// Set to true (default) in order to send the body to the | ||
/// redirected URL, unless the force verb to GET behavior is triggered. | ||
/// <see cref="ForceForwardBody"/> | ||
/// </summary> | ||
public bool ForwardBody { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Set to true (default is false) to force forwarding the body of the | ||
/// request even when normally, the verb might be altered to GET based | ||
/// on backward compatiblity with browser processing of HTTP status codes. | ||
/// </summary> | ||
/// <remarks> | ||
/// Based on Wikipedia https://en.wikipedia.org/wiki/HTTP_302: | ||
/// <pre> | ||
/// Many web browsers implemented this code in a manner that violated this standard, changing | ||
/// the request type of the new request to GET, regardless of the type employed in the original request | ||
/// (e.g. POST). For this reason, HTTP/1.1 (RFC 2616) added the new status codes 303 and 307 to disambiguate | ||
/// between the two behaviours, with 303 mandating the change of request type to GET, and 307 preserving the | ||
/// request type as originally sent. Despite the greater clarity provided by this disambiguation, the 302 code | ||
/// is still employed in web frameworks to preserve compatibility with browsers that do not implement the HTTP/1.1 | ||
/// specification. | ||
/// </pre> | ||
/// </remarks> | ||
public bool ForceForwardBody { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Set to true (default) to forward the query string to the redirected URL. | ||
/// </summary> | ||
public bool ForwardQuery { get; set; } = true; | ||
|
||
/// <summary> | ||
/// The maximum number of redirects to follow. | ||
/// </summary> | ||
public int MaxRedirects { get; set; } = 50; | ||
|
||
/// <summary> | ||
/// Set to true (default), to supply any requested fragment portion of the original URL to the destination URL. | ||
/// </summary> | ||
/// <remarks> | ||
/// Per https://tools.ietf.org/html/rfc7231#section-7.1.2, a redirect location without a | ||
/// fragment should inherit the fragment from the original URI. | ||
/// </remarks> | ||
public bool ForwardFragment { get; set; } = true; | ||
|
||
/// <summary> | ||
/// Set to true (default), to allow the HTTP Method used on the original request to | ||
/// be replaced with GET when the status code 303 (HttpStatusCode.RedirectMethod) | ||
/// was returned. Setting this to false will disallow the altering of the verb. | ||
/// </summary> | ||
public bool AllowRedirectMethodStatusCodeToAlterVerb { get; set; } = true; | ||
|
||
/// <summary> | ||
/// Set to true (default), to allow the backward compatibility behavior of | ||
/// changing the verb to GET with non 303 redirection status codes. | ||
/// </summary> | ||
/// <remarks> | ||
/// NOTE: Even though the below text only references 302, this also allows some other scenarios. | ||
/// See <see cref="RestClient.RedirectRequestRequiresForceGet(HttpStatusCode, HttpMethod)"/> for the specifics. | ||
/// Based on Wikipedia https://en.wikipedia.org/wiki/HTTP_302: | ||
/// Many web browsers implemented this code in a manner that violated this standard, changing | ||
/// the request type of the new request to GET, regardless of the type employed in the original request | ||
/// (e.g. POST). For this reason, HTTP/1.1 (RFC 2616) added the new status codes 303 and 307 to disambiguate | ||
/// between the two behaviours, with 303 mandating the change of request type to GET, and 307 preserving the | ||
/// request type as originally sent. Despite the greater clarity provided by this disambiguation, the 302 code | ||
/// is still employed in web frameworks to preserve compatibility with browsers that do not implement the HTTP/1.1 | ||
/// specification. | ||
/// </remarks> | ||
public bool AllowForcedRedirectVerbChange { get; set; } = true; | ||
|
||
/// <summary> | ||
/// HttpStatusCodes that trigger redirect processing. Defaults to MovedPermanently (301), | ||
/// SeeOther/RedirectMethod (303), | ||
/// TemporaryRedirect (307), | ||
/// Redirect (302), | ||
/// PermanentRedirect (308) | ||
/// </summary> | ||
public IReadOnlyList<HttpStatusCode> RedirectStatusCodes { get; set; } | ||
|
||
public RestClientRedirectionOptions() { | ||
RedirectStatusCodes = new List<HttpStatusCode>() { | ||
HttpStatusCode.MovedPermanently, | ||
HttpStatusCode.SeeOther, | ||
HttpStatusCode.TemporaryRedirect, | ||
HttpStatusCode.Redirect, | ||
#if NET | ||
HttpStatusCode.PermanentRedirect, | ||
#endif | ||
}.AsReadOnly(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this
s
needs to go?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Fixed locally.