Skip to content

Commit 190d207

Browse files
committed
Add new files..
1 parent 0db3d87 commit 190d207

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using RestSharp.Extensions;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Net;
5+
using System.Reflection;
6+
using System.Text;
7+
8+
namespace RestSharp.Options {
9+
[GenerateImmutable]
10+
public class RestClientRedirectionOptions {
11+
static readonly Version Version = new AssemblyName(typeof(RestClientOptions).Assembly.FullName!).Version!;
12+
13+
public bool FollowRedirects { get; set; } = true;
14+
public bool FollowRedirectsToInsecure { get; set; } = false;
15+
public bool ForwardHeaders { get; set; } = true;
16+
public bool ForwardAuthorization { get; set; } = false;
17+
public bool ForwardCookies { get; set; } = true;
18+
public bool ForwardBody { get; set; } = true;
19+
public bool ForwardQuery { get; set; } = true;
20+
public int MaxRedirects { get; set; }
21+
public bool ForwardFragment { get; set; } = true;
22+
public IReadOnlyList<HttpStatusCode> RedirectStatusCodes { get; set; }
23+
24+
public RestClientRedirectionOptions() {
25+
RedirectStatusCodes = new List<HttpStatusCode>() {
26+
HttpStatusCode.MovedPermanently,
27+
HttpStatusCode.SeeOther,
28+
HttpStatusCode.TemporaryRedirect,
29+
HttpStatusCode.Redirect,
30+
#if NET
31+
HttpStatusCode.PermanentRedirect,
32+
#endif
33+
}.AsReadOnly();
34+
}
35+
}
36+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.Extensions.Logging;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Net;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace RestSharp.Tests.Integrated.Server.Handlers;
11+
12+
/// <summary>
13+
/// An <see cref="IResult"/> that returns a redirection with a supplied status code value.
14+
/// Created in order to easily return a SeeOther status code.
15+
/// </summary>
16+
class RedirectWithStatusCodeResult : IResult {
17+
public int StatusCode { get; }
18+
public string Uri { get; }
19+
20+
public RedirectWithStatusCodeResult(int statusCode, string url) {
21+
Uri = url;
22+
StatusCode = statusCode;
23+
}
24+
25+
public Task ExecuteAsync(HttpContext httpContext) {
26+
ArgumentNullException.ThrowIfNull(httpContext);
27+
28+
httpContext.Response.StatusCode = StatusCode;
29+
httpContext.Response.Headers.Location = Uri;
30+
31+
return Task.CompletedTask;
32+
}
33+
}

0 commit comments

Comments
 (0)