Skip to content

完善OpenSslSocketsHttpHandler#3

Open
xljiulang wants to merge 2 commits into
dotnet-campus:mainfrom
xljiulang:httphandler
Open

完善OpenSslSocketsHttpHandler#3
xljiulang wants to merge 2 commits into
dotnet-campus:mainfrom
xljiulang:httphandler

Conversation

@xljiulang

Copy link
Copy Markdown
Contributor

此PR以最大限度地支持ConnectCallback的连接完整性,同时修复了#2

  • OpenSslSocketsHttpHandler基于DelegatingHandler,使用 SocketsHttpHandler 做为 innerHandler
  • 拥有完善的相关属性,开放 OpenSslClientAuthenticationOptions 做为其 SslOptions 属性
  • 拦截 ConnectCallback (windows only) 的同时提供完整的 Proxy 实现
  • HttpRequestOptions 在请求完成后自动清理

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@lindexi lindexi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢贡献,这个 PR 有些大,容我看一段时间

/// 通过已注册的 DllImportResolver 尝试加载 libssl-3,不抛出异常。
/// </summary>
/// <remarks>
/// 读取此属性会触发静态构造函数,确保 DllImportResolver 已注册。

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 这里不是属性,而是方法
  2. 应该不会触发静态构造函数吧,打个断点试试?


public static bool IsSupported { get; } = OperatingSystem.IsWindows() && OpenSSLNative.IsOpenSslAvailable();

public OpenSslAsyncStream(NetworkStream innerStream, bool leaveInnerStreamOpen)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉这个构造函数的设计不妙,是否可以直接就绕过了?不要再走这里的构造函数进来

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在代理环境下,需要stream套娃。此构造也是stream套娃,保持 NetworkStream 的引用和生命周期同步;而传入 Socket 的构造器反正不是很需要

private bool _isAuthenticated;
private bool _disposed;

public static bool IsSupported { get; } = OperatingSystem.IsWindows() && OpenSSLNative.IsOpenSslAvailable();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个很棒,可以来做快速分支,只是我想着可以直接用计算的方式,就不用后备字段:

Suggested change
public static bool IsSupported { get; } = OperatingSystem.IsWindows() && OpenSSLNative.IsOpenSslAvailable();
public static bool IsSupported => OperatingSystem.IsWindows() && OpenSSLNative.IsOpenSslAvailable();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前没有做过NativeLibrary.TryLoad的开销计算,IsSupported做为字段存储已计算过的值可以避开不确定的开销。如果不存储已计算过的值,我更倾向于直接设计成IsSupported()方法

/// OpenSSL 客户端认证配置选项。
/// </summary>
internal sealed class OpenSslClientAuthenticationOptions
public sealed class OpenSslClientAuthenticationOptions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是为什么要开放呢?我静态阅读代码没有看全哈

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是要开放给httphandler做为ssl选项属性

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants