Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit e43ccc6

Browse files
committed
Make OriginalUrl readonly.
Add a new property (RequestUriString) which can be overridden in user code
1 parent 7b5ee1c commit e43ccc6

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

src/Titanium.Web.Proxy/Helpers/HttpRequestWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal HttpRequestWriter(Stream stream, IBufferPool bufferPool, int bufferSize
2323
internal async Task WriteRequestAsync(Request request, bool flush = true,
2424
CancellationToken cancellationToken = default)
2525
{
26-
await WriteLineAsync(Request.CreateRequestLine(request.Method, request.OriginalUrl, request.HttpVersion),
26+
await WriteLineAsync(Request.CreateRequestLine(request.Method, request.RequestUriString, request.HttpVersion),
2727
cancellationToken);
2828
await WriteAsync(request, flush, cancellationToken);
2929
}

src/Titanium.Web.Proxy/Http/HttpWebClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ internal async Task SendRequest(bool enable100ContinueBehaviour, bool isTranspar
9999

100100
// prepare the request & headers
101101
await writer.WriteLineAsync(Request.CreateRequestLine(Request.Method,
102-
useUpstreamProxy || isTransparent ? Request.OriginalUrl : Request.RequestUri.PathAndQuery,
102+
useUpstreamProxy || isTransparent ? Request.RequestUriString : Request.RequestUri.PathAndQuery,
103103
Request.HttpVersion), cancellationToken);
104104

105105
var headerBuilder = new StringBuilder();

src/Titanium.Web.Proxy/Http/Request.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace Titanium.Web.Proxy.Http
1414
[TypeConverter(typeof(ExpandableObjectConverter))]
1515
public class Request : RequestResponseBase
1616
{
17+
private string originalUrl;
18+
1719
/// <summary>
1820
/// Request Method.
1921
/// </summary>
@@ -32,7 +34,20 @@ public class Request : RequestResponseBase
3234
/// <summary>
3335
/// The original request Url.
3436
/// </summary>
35-
public string OriginalUrl { get; set; }
37+
public string OriginalUrl
38+
{
39+
get => originalUrl;
40+
internal set
41+
{
42+
originalUrl = value;
43+
RequestUriString = value;
44+
}
45+
}
46+
47+
/// <summary>
48+
/// The request uri as it is in the HTTP header
49+
/// </summary>
50+
public string RequestUriString { get; set; }
3651

3752
/// <summary>
3853
/// Has request body?
@@ -140,7 +155,7 @@ public override string HeaderText
140155
get
141156
{
142157
var sb = new StringBuilder();
143-
sb.Append($"{CreateRequestLine(Method, OriginalUrl, HttpVersion)}{ProxyConstants.NewLine}");
158+
sb.Append($"{CreateRequestLine(Method, RequestUriString, HttpVersion)}{ProxyConstants.NewLine}");
144159
foreach (var header in Headers)
145160
{
146161
sb.Append($"{header.ToString()}{ProxyConstants.NewLine}");

src/Titanium.Web.Proxy/ResponseHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private async Task handleHttpSessionResponse(SessionEventArgs args)
9292
// clear current response
9393
await args.ClearResponse(cancellationToken);
9494
var httpCmd = Request.CreateRequestLine(args.HttpClient.Request.Method,
95-
args.HttpClient.Request.OriginalUrl, args.HttpClient.Request.HttpVersion);
95+
args.HttpClient.Request.RequestUriString, args.HttpClient.Request.HttpVersion);
9696
await handleHttpSessionRequest(httpCmd, args, null, args.ClientConnection.NegotiatedApplicationProtocol,
9797
cancellationToken, args.CancellationTokenSource);
9898
return;

tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpContinueClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public async Task<Response> Post(string server, int port, string content)
2020
var request = new Request
2121
{
2222
Method = "POST",
23-
OriginalUrl = "/",
23+
RequestUriString = "/",
2424
HttpVersion = new Version(1, 1)
2525
};
2626
request.Headers.AddHeader(KnownHeaders.Host, server);

tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpMessageParsing.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal static Request ParseRequest(string messageText, bool requireBody)
2626
RequestResponseBase request = new Request()
2727
{
2828
Method = method,
29-
OriginalUrl = url,
29+
RequestUriString = url,
3030
HttpVersion = version
3131
};
3232
while (!string.IsNullOrEmpty(line = reader.ReadLine()))

0 commit comments

Comments
 (0)