Commit e43ccc62 authored by Honfika's avatar Honfika

Make OriginalUrl readonly.

Add a new property (RequestUriString) which can be overridden in user code
parent 7b5ee1ca
...@@ -23,7 +23,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -23,7 +23,7 @@ namespace Titanium.Web.Proxy.Helpers
internal async Task WriteRequestAsync(Request request, bool flush = true, internal async Task WriteRequestAsync(Request request, bool flush = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
await WriteLineAsync(Request.CreateRequestLine(request.Method, request.OriginalUrl, request.HttpVersion), await WriteLineAsync(Request.CreateRequestLine(request.Method, request.RequestUriString, request.HttpVersion),
cancellationToken); cancellationToken);
await WriteAsync(request, flush, cancellationToken); await WriteAsync(request, flush, cancellationToken);
} }
......
...@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy.Http
// prepare the request & headers // prepare the request & headers
await writer.WriteLineAsync(Request.CreateRequestLine(Request.Method, await writer.WriteLineAsync(Request.CreateRequestLine(Request.Method,
useUpstreamProxy || isTransparent ? Request.OriginalUrl : Request.RequestUri.PathAndQuery, useUpstreamProxy || isTransparent ? Request.RequestUriString : Request.RequestUri.PathAndQuery,
Request.HttpVersion), cancellationToken); Request.HttpVersion), cancellationToken);
var headerBuilder = new StringBuilder(); var headerBuilder = new StringBuilder();
......
...@@ -14,6 +14,8 @@ namespace Titanium.Web.Proxy.Http ...@@ -14,6 +14,8 @@ namespace Titanium.Web.Proxy.Http
[TypeConverter(typeof(ExpandableObjectConverter))] [TypeConverter(typeof(ExpandableObjectConverter))]
public class Request : RequestResponseBase public class Request : RequestResponseBase
{ {
private string originalUrl;
/// <summary> /// <summary>
/// Request Method. /// Request Method.
/// </summary> /// </summary>
...@@ -32,7 +34,20 @@ namespace Titanium.Web.Proxy.Http ...@@ -32,7 +34,20 @@ namespace Titanium.Web.Proxy.Http
/// <summary> /// <summary>
/// The original request Url. /// The original request Url.
/// </summary> /// </summary>
public string OriginalUrl { get; set; } public string OriginalUrl
{
get => originalUrl;
internal set
{
originalUrl = value;
RequestUriString = value;
}
}
/// <summary>
/// The request uri as it is in the HTTP header
/// </summary>
public string RequestUriString { get; set; }
/// <summary> /// <summary>
/// Has request body? /// Has request body?
...@@ -140,7 +155,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -140,7 +155,7 @@ namespace Titanium.Web.Proxy.Http
get get
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
sb.Append($"{CreateRequestLine(Method, OriginalUrl, HttpVersion)}{ProxyConstants.NewLine}"); sb.Append($"{CreateRequestLine(Method, RequestUriString, HttpVersion)}{ProxyConstants.NewLine}");
foreach (var header in Headers) foreach (var header in Headers)
{ {
sb.Append($"{header.ToString()}{ProxyConstants.NewLine}"); sb.Append($"{header.ToString()}{ProxyConstants.NewLine}");
......
...@@ -92,7 +92,7 @@ namespace Titanium.Web.Proxy ...@@ -92,7 +92,7 @@ namespace Titanium.Web.Proxy
// clear current response // clear current response
await args.ClearResponse(cancellationToken); await args.ClearResponse(cancellationToken);
var httpCmd = Request.CreateRequestLine(args.HttpClient.Request.Method, var httpCmd = Request.CreateRequestLine(args.HttpClient.Request.Method,
args.HttpClient.Request.OriginalUrl, args.HttpClient.Request.HttpVersion); args.HttpClient.Request.RequestUriString, args.HttpClient.Request.HttpVersion);
await handleHttpSessionRequest(httpCmd, args, null, args.ClientConnection.NegotiatedApplicationProtocol, await handleHttpSessionRequest(httpCmd, args, null, args.ClientConnection.NegotiatedApplicationProtocol,
cancellationToken, args.CancellationTokenSource); cancellationToken, args.CancellationTokenSource);
return; return;
......
...@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers ...@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers
var request = new Request var request = new Request
{ {
Method = "POST", Method = "POST",
OriginalUrl = "/", RequestUriString = "/",
HttpVersion = new Version(1, 1) HttpVersion = new Version(1, 1)
}; };
request.Headers.AddHeader(KnownHeaders.Host, server); request.Headers.AddHeader(KnownHeaders.Host, server);
......
...@@ -26,7 +26,7 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers ...@@ -26,7 +26,7 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers
RequestResponseBase request = new Request() RequestResponseBase request = new Request()
{ {
Method = method, Method = method,
OriginalUrl = url, RequestUriString = url,
HttpVersion = version HttpVersion = version
}; };
while (!string.IsNullOrEmpty(line = reader.ReadLine())) while (!string.IsNullOrEmpty(line = reader.ReadLine()))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment