Unverified Commit e05318f4 authored by honfika's avatar honfika Committed by GitHub

Merge pull request #687 from justcoding121/master

beta
parents f3ab526d dd0a19ad
......@@ -58,7 +58,7 @@ namespace Titanium.Web.Proxy
return;
}
var connectRequest = new ConnectRequest(requestLine.RequestUri.GetString())
var connectRequest = new ConnectRequest(requestLine.RequestUri)
{
RequestUriString8 = requestLine.RequestUri,
HttpVersion = requestLine.Version
......@@ -269,7 +269,12 @@ namespace Titanium.Web.Proxy
try
{
// clientStream.Available should be at most BufferSize because it is using the same buffer size
await clientStream.ReadAsync(data, 0, available, cancellationToken);
int read = await clientStream.ReadAsync(data, 0, available, cancellationToken);
if (read != available)
{
throw new Exception("Internal error.");
}
await connection.Stream.WriteAsync(data, 0, available, true, cancellationToken);
}
finally
......
using System;
using Titanium.Web.Proxy.Extensions;
using Titanium.Web.Proxy.Models;
using Titanium.Web.Proxy.StreamExtended;
namespace Titanium.Web.Proxy.Http
......@@ -9,7 +10,7 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
public class ConnectRequest : Request
{
public ConnectRequest(string authority)
internal ConnectRequest(ByteString authority)
{
Method = "CONNECT";
Authority = authority;
......
......@@ -40,7 +40,7 @@ namespace Titanium.Web.Proxy.Http
}
}
internal string? Authority { get; set; }
internal ByteString Authority { get; set; }
/// <summary>
/// Request HTTP Uri.
......@@ -75,7 +75,7 @@ namespace Titanium.Web.Proxy.Http
string url = RequestUriString8.GetString();
if (getUriScheme(RequestUriString8).Length == 0)
{
string? hostAndPath = Host ?? Authority;
string? hostAndPath = Host ?? Authority.GetString();
if (url.StartsWith("/"))
{
......
......@@ -264,7 +264,7 @@ namespace Titanium.Web.Proxy.Http2
request.HttpVersion = HttpVersion.Version20;
request.Method = method.GetString();
request.IsHttps = headerListener.Scheme == ProxyServer.UriSchemeHttps;
request.Authority = headerListener.Authority.GetString();
request.Authority = headerListener.Authority;
request.RequestUriString8 = path;
//request.RequestUri = headerListener.GetUri();
......@@ -475,7 +475,7 @@ namespace Titanium.Web.Proxy.Http2
encoder.EncodeHeader(writer, StaticTable.KnownHeaderMethod, request.Method.GetByteString());
encoder.EncodeHeader(writer, StaticTable.KnownHeaderAuhtority, uri.Authority.GetByteString());
encoder.EncodeHeader(writer, StaticTable.KnownHeaderScheme, uri.Scheme.GetByteString());
encoder.EncodeHeader(writer, StaticTable.KnownHeaderPath, request.Url.GetByteString(), false,
encoder.EncodeHeader(writer, StaticTable.KnownHeaderPath, request.RequestUriString8, false,
HpackUtil.IndexType.None, false);
}
else
......
using System;
using System.Text;
using Titanium.Web.Proxy.Extensions;
namespace Titanium.Web.Proxy.Models
{
......@@ -28,11 +29,31 @@ namespace Titanium.Web.Proxy.Models
return Data.Span.SequenceEqual(other.Data.Span);
}
public int IndexOf(byte value)
{
return Span.IndexOf(value);
}
public ByteString Slice(int start)
{
return Data.Slice(start);
}
public ByteString Slice(int start, int length)
{
return Data.Slice(start, length);
}
public override int GetHashCode()
{
return Data.GetHashCode();
}
public override string ToString()
{
return this.GetString();
}
public static explicit operator ByteString(string str) => new ByteString(Encoding.ASCII.GetBytes(str));
public static implicit operator ByteString(byte[] data) => new ByteString(data);
......
......@@ -180,10 +180,34 @@ namespace Titanium.Web.Proxy.Network.Tcp
session.CustomUpStreamProxyUsed = customUpStreamProxy;
var uri = session.HttpClient.Request.RequestUri;
var request = session.HttpClient.Request;
string host;
int port;
if (request.Authority.Length > 0)
{
var authority = request.Authority;
int idx = authority.IndexOf((byte)':');
if (idx == -1)
{
host = authority.GetString();
port = 80;
}
else
{
host = authority.Slice(0, idx).GetString();
port = int.Parse(authority.Slice(idx + 1).GetString());
}
}
else
{
var uri = request.RequestUri;
host = uri.Host;
port = uri.Port;
}
return await GetServerConnection(
uri.Host,
uri.Port,
host,
port,
session.HttpClient.Request.HttpVersion,
isHttps, applicationProtocols, isConnect,
server, session, session.HttpClient.UpStreamEndPoint ?? server.UpStreamEndPoint,
......@@ -426,11 +450,11 @@ retry:
if (externalProxy != null && (isConnect || isHttps))
{
string authority = $"{remoteHostName}:{remotePort}";
var authority = $"{remoteHostName}:{remotePort}".GetByteString();
var connectRequest = new ConnectRequest(authority)
{
IsHttps = isHttps,
RequestUriString8 = HttpHeader.Encoding.GetBytes(authority),
RequestUriString8 = authority,
HttpVersion = httpVersion
};
......
......@@ -216,7 +216,7 @@ namespace Titanium.Web.Proxy.StreamExtended
int recordLength = ((recordType & 0x7f) << 8) + peekStream.ReadByte();
if (recordLength < 38)
{
// Message body too short.
// Message body too short.
return null;
}
......
......@@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="BrotliSharpLib" Version="0.3.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5.2" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
</ItemGroup>
......
......@@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="BrotliSharpLib" Version="0.3.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5.2" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
</ItemGroup>
......
......@@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="BrotliSharpLib" Version="0.3.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5.2" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.1'">
......
......@@ -16,14 +16,14 @@
<dependencies>
<group targetFramework="net45">
<dependency id="BrotliSharpLib" version="0.3.3" />
<dependency id="Portable.BouncyCastle" version="1.8.5" />
<dependency id="Portable.BouncyCastle" version="1.8.5.2" />
<dependency id="System.Buffers" version="4.5.0" />
<dependency id="System.Memory" version="4.5.3" />
<dependency id="System.Threading.Tasks.Extensions" version="4.5.3" />
</group>
<group targetFramework="net461">
<dependency id="BrotliSharpLib" version="0.3.3" />
<dependency id="Portable.BouncyCastle" version="1.8.5" />
<dependency id="Portable.BouncyCastle" version="1.8.5.2" />
<dependency id="Microsoft.Win32.Registry" version="4.6.0" />
<dependency id="System.Buffers" version="4.5.0" />
<dependency id="System.Memory" version="4.5.3" />
......@@ -32,7 +32,7 @@
</group>
<group targetFramework="netstandard2.0">
<dependency id="BrotliSharpLib" version="0.3.3" />
<dependency id="Portable.BouncyCastle" version="1.8.5" />
<dependency id="Portable.BouncyCastle" version="1.8.5.2" />
<dependency id="Microsoft.Win32.Registry" version="4.6.0" />
<dependency id="System.Buffers" version="4.5.0" />
<dependency id="System.Memory" version="4.5.3" />
......@@ -41,7 +41,7 @@
</group>
<group targetFramework="netstandard2.1">
<dependency id="BrotliSharpLib" version="0.3.3" />
<dependency id="Portable.BouncyCastle" version="1.8.5" />
<dependency id="Portable.BouncyCastle" version="1.8.5.2" />
<dependency id="Microsoft.Win32.Registry" version="4.6.0" />
<dependency id="System.Security.Principal.Windows" version="4.6.0" />
</group>
......
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