Skip to content

Commit

Permalink
[browser][wasm] Wasm address miscellaneous code comments (dotnet#37235)
Browse files Browse the repository at this point in the history
* Remove custom messages being passed to PNSE.

* Address miscellaneous code review comments

- Remove unnecessary sealed
- implement Properties instead of throwing PNSE
- refactoring to avoid the explicit static cctor

* Add extra new line at end of file

* Remove TODO comments
  • Loading branch information
kjpou1 authored Jun 2, 2020
1 parent 93b6c44 commit b6d8ebd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ internal sealed class BrowserHttpHandler : HttpMessageHandler
/// <summary>
/// Gets whether the current Browser supports streaming responses
/// </summary>
private static bool StreamingSupported { get; }

static BrowserHttpHandler()
private static bool StreamingSupported { get; } = GetIsStreamingSupported();
private static bool GetIsStreamingSupported()
{
using (var streamingSupported = new Function("return typeof Response !== 'undefined' && 'body' in Response.prototype && typeof ReadableStream === 'function'"))
StreamingSupported = (bool)streamingSupported.Call();
return (bool)streamingSupported.Call();
}

public bool UseCookies
Expand Down Expand Up @@ -122,7 +121,8 @@ public SslClientAuthenticationOptions SslOptions
set => throw new PlatformNotSupportedException();
}

public IDictionary<string, object?> Properties => throw new PlatformNotSupportedException();
private Dictionary<string, object?>? _properties;
public IDictionary<string, object?> Properties => _properties ??= new Dictionary<string, object?>();

protected internal override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -367,7 +367,7 @@ protected override async Task<Stream> CreateContentReadStreamAsync()

protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context) =>
SerializeToStreamAsync(stream, context, CancellationToken.None);
protected sealed override async Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken cancellationToken)
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken cancellationToken)
{
byte[] data = await GetResponseData().ConfigureAwait(continueOnCapturedContext: true);
await stream.WriteAsync(data, 0, data.Length, cancellationToken).ConfigureAwait(continueOnCapturedContext: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,123 +14,123 @@ public sealed class SocketsHttpHandler : HttpMessageHandler
{
public bool UseCookies
{
get => throw new PlatformNotSupportedException("Property UseCookies is not supported.");
set => throw new PlatformNotSupportedException("Property UseCookies is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

[AllowNull]
public CookieContainer CookieContainer
{
get => throw new PlatformNotSupportedException("Property CookieContainer is not supported.");
set => throw new PlatformNotSupportedException("Property CookieContainer is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public DecompressionMethods AutomaticDecompression
{
get => throw new PlatformNotSupportedException("Property AutomaticDecompression is not supported.");
set => throw new PlatformNotSupportedException("Property AutomaticDecompression is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public bool UseProxy
{
get => throw new PlatformNotSupportedException("Property UseProxy is not supported.");
set => throw new PlatformNotSupportedException("Property UseProxy is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public IWebProxy? Proxy
{
get => throw new PlatformNotSupportedException("Property Proxy is not supported.");
set => throw new PlatformNotSupportedException("Property Proxy is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public ICredentials? DefaultProxyCredentials
{
get => throw new PlatformNotSupportedException("Property Credentials is not supported.");
set => throw new PlatformNotSupportedException("Property Credentials is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public bool PreAuthenticate
{
get => throw new PlatformNotSupportedException("Property PreAuthenticate is not supported.");
set => throw new PlatformNotSupportedException("Property PreAuthenticate is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public ICredentials? Credentials
{
get => throw new PlatformNotSupportedException("Property Credentials is not supported.");
set => throw new PlatformNotSupportedException("Property Credentials is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public bool AllowAutoRedirect
{
get => throw new PlatformNotSupportedException("Property AllowAutoRedirect is not supported.");
set => throw new PlatformNotSupportedException("Property AllowAutoRedirect is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public int MaxAutomaticRedirections
{
get => throw new PlatformNotSupportedException("Property MaxAutomaticRedirections is not supported.");
set => throw new PlatformNotSupportedException("Property MaxAutomaticRedirections is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public int MaxConnectionsPerServer
{
get => throw new PlatformNotSupportedException("Property MaxConnectionsPerServer is not supported.");
set => throw new PlatformNotSupportedException("Property MaxConnectionsPerServer is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public int MaxResponseDrainSize
{
get => throw new PlatformNotSupportedException("Property MaxResponseDrainSize is not supported.");
set => throw new PlatformNotSupportedException("Property MaxResponseDrainSize is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public TimeSpan ResponseDrainTimeout
{
get => throw new PlatformNotSupportedException("Property ResponseDrainTimeout is not supported.");
set => throw new PlatformNotSupportedException("Property ResponseDrainTimeout is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public int MaxResponseHeadersLength
{
get => throw new PlatformNotSupportedException("Property MaxResponseHeadersLength is not supported.");
set => throw new PlatformNotSupportedException("Property MaxResponseHeadersLength is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

[AllowNull]
public SslClientAuthenticationOptions SslOptions
{
get => throw new PlatformNotSupportedException("Property SslOptions is not supported.");
set => throw new PlatformNotSupportedException("Property SslOptions is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public TimeSpan PooledConnectionLifetime
{
get => throw new PlatformNotSupportedException("Property PooledConnectionLifetime is not supported.");
set => throw new PlatformNotSupportedException("Property PooledConnectionLifetime is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public TimeSpan PooledConnectionIdleTimeout
{
get => throw new PlatformNotSupportedException("Property PooledConnectionLifetime is not supported.");
set => throw new PlatformNotSupportedException("Property PooledConnectionLifetime is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public TimeSpan ConnectTimeout
{
get => throw new PlatformNotSupportedException("Property ConnectTimeout is not supported.");
set => throw new PlatformNotSupportedException("Property ConnectTimeout is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public TimeSpan Expect100ContinueTimeout
{
get => throw new PlatformNotSupportedException("Property Expect100ContinueTimeout is not supported.");
set => throw new PlatformNotSupportedException("Property Expect100ContinueTimeout is not supported.");
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public IDictionary<string, object?> Properties => throw new PlatformNotSupportedException("Property Properties is not supported.");
public IDictionary<string, object?> Properties => throw new PlatformNotSupportedException();

protected internal override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken) => throw new PlatformNotSupportedException("Method SendAsync is not supported.");
HttpRequestMessage request, CancellationToken cancellationToken) => throw new PlatformNotSupportedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsNETCoreApp>true</IsNETCoreApp>
</PropertyGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,13 @@ private void Dispose(bool disposing)
{
if (!_disposedValue)
{
if (disposing)
{
// TODO: dispose managed state (managed objects).
}

// TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
// TODO: set large fields to null.
_mapItemIterator?.Dispose();
_mapItemIterator = null;
_disposedValue = true;
}
}

//TODO: override a finalizer only if Dispose (bool disposing) above has code to free unmanaged resources.
~MapItemEnumerator()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Expand Down

0 comments on commit b6d8ebd

Please sign in to comment.