Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ internal class CFProxy
{
private SafeCFDictionaryHandle _dictionary;

internal static readonly string kCFProxyTypeAutoConfigurationURL;
internal static readonly string kCFProxyTypeAutoConfigurationJavaScript;
internal static readonly string kCFProxyTypeFTP;
internal static readonly string kCFProxyTypeHTTP;
internal static readonly string kCFProxyTypeHTTPS;
internal static readonly string kCFProxyTypeSOCKS;
internal static readonly string? kCFProxyTypeAutoConfigurationURL;
internal static readonly string? kCFProxyTypeAutoConfigurationJavaScript;
internal static readonly string? kCFProxyTypeFTP;
internal static readonly string? kCFProxyTypeHTTP;
internal static readonly string? kCFProxyTypeHTTPS;
internal static readonly string? kCFProxyTypeSOCKS;

private static readonly IntPtr kCFProxyAutoConfigurationJavaScriptKey;
private static readonly IntPtr kCFProxyAutoConfigurationURLKey;
Expand Down Expand Up @@ -109,7 +109,7 @@ private static string LoadCFStringSymbol(IntPtr lib, string name)
}
}

private string GetString(IntPtr key)
private string? GetString(IntPtr key)
{
IntPtr dictValue = CFDictionaryGetValue(_dictionary, key);
if (dictValue != IntPtr.Zero)
Expand All @@ -122,10 +122,10 @@ private string GetString(IntPtr key)
return null;
}

public string ProxyType => GetString(kCFProxyTypeKey);
public string HostName => GetString(kCFProxyHostNameKey);
public string Username => GetString(kCFProxyUsernameKey);
public string Password => GetString(kCFProxyPasswordKey);
public string? ProxyType => GetString(kCFProxyTypeKey);
public string? HostName => GetString(kCFProxyHostNameKey);
public string? Username => GetString(kCFProxyUsernameKey);
public string? Password => GetString(kCFProxyPasswordKey);

public int PortNumber
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
Expand All @@ -14,13 +15,13 @@ internal partial class WinHttp
{
internal class SafeWinHttpHandle : SafeHandleZeroOrMinusOneIsInvalid
{
private SafeWinHttpHandle _parentHandle = null;
private SafeWinHttpHandle? _parentHandle = null;

public SafeWinHttpHandle() : base(true)
{
}

public static void DisposeAndClearHandle(ref SafeWinHttpHandle safeHandle)
public static void DisposeAndClearHandle(ref SafeWinHttpHandle? safeHandle)
{
if (safeHandle != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;
using System.Runtime.InteropServices;
using System.Text;
Expand Down Expand Up @@ -189,7 +190,7 @@ public static extern bool WinHttpGetIEProxyConfigForCurrentUser(
[DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool WinHttpGetProxyForUrl(
SafeWinHttpHandle sessionHandle, string url,
SafeWinHttpHandle? sessionHandle, string url,
ref WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions,
out WINHTTP_PROXY_INFO proxyInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;
using System.Runtime.InteropServices;
using System.Text;
Expand Down Expand Up @@ -239,7 +240,7 @@ public struct WINHTTP_AUTOPROXY_OPTIONS
public uint Flags;
public uint AutoDetectFlags;
[MarshalAs(UnmanagedType.LPWStr)]
public string AutoConfigUrl;
public string? AutoConfigUrl;
public IntPtr Reserved1;
public uint Reserved2;
[MarshalAs(UnmanagedType.Bool)]
Expand Down
5 changes: 3 additions & 2 deletions src/libraries/Common/src/System/IO/DelegatingStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Diagnostics;
using System.IO;
using System.Threading;
Expand Down Expand Up @@ -113,7 +114,7 @@ public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken
return _innerStream.ReadAsync(buffer, cancellationToken);
}

public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
{
return _innerStream.BeginRead(buffer, offset, count, callback, state);
}
Expand Down Expand Up @@ -167,7 +168,7 @@ public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationTo
return _innerStream.WriteAsync(buffer, cancellationToken);
}

public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
{
return _innerStream.BeginWrite(buffer, offset, count, callback, state);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/System/IO/ReadOnlyMemoryStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public override Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancel
new ValueTask<int>(Task.FromCanceled<int>(cancellationToken)) :
new ValueTask<int>(Read(buffer.Span));

public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) =>
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) =>
TaskToApm.Begin(ReadAsync(buffer, offset, count), callback, state);

public override int EndRead(IAsyncResult asyncResult) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Diagnostics;
using System.IO;
using System.Threading;
Expand All @@ -26,15 +27,15 @@ internal NoWriteNoSeekStreamContent(Stream content)
_content = content;
}

protected override Task SerializeToStreamAsync(Stream stream, TransportContext context) =>
protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context) =>
SerializeToStreamAsync(stream, context, CancellationToken.None);

#if NETCOREAPP
protected override
#else
internal
#endif
Task SerializeToStreamAsync(Stream stream, TransportContext context, CancellationToken cancellationToken)
Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken cancellationToken)
{
Debug.Assert(stream != null);

Expand All @@ -54,7 +55,7 @@ Task SerializeToStreamAsync(Stream stream, TransportContext context, Cancellatio
{
copyTask = copyTask.ContinueWith((t, s) =>
{
try { ((Stream)s).Dispose(); } catch { }
try { ((Stream)s!).Dispose(); } catch { }
t.GetAwaiter().GetResult();
}, _content, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
}
Expand Down
19 changes: 10 additions & 9 deletions src/libraries/Common/src/System/Net/Http/WinInetProxyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;
using System.Runtime.InteropServices;

Expand All @@ -14,7 +15,7 @@ namespace System.Net.Http
internal class WinInetProxyHelper
{
private const int RecentAutoDetectionInterval = 120_000; // 2 minutes in milliseconds.
private readonly string _autoConfigUrl, _proxy, _proxyBypass;
private readonly string? _autoConfigUrl, _proxy, _proxyBypass;
private readonly bool _autoDetect;
private readonly bool _useProxy = false;
private bool _autoDetectionFailed;
Expand All @@ -28,10 +29,10 @@ public WinInetProxyHelper()
{
if (Interop.WinHttp.WinHttpGetIEProxyConfigForCurrentUser(out proxyConfig))
{
_autoConfigUrl = Marshal.PtrToStringUni(proxyConfig.AutoConfigUrl);
_autoConfigUrl = Marshal.PtrToStringUni(proxyConfig.AutoConfigUrl)!;
_autoDetect = proxyConfig.AutoDetect;
_proxy = Marshal.PtrToStringUni(proxyConfig.Proxy);
_proxyBypass = Marshal.PtrToStringUni(proxyConfig.ProxyBypass);
_proxy = Marshal.PtrToStringUni(proxyConfig.Proxy)!;
_proxyBypass = Marshal.PtrToStringUni(proxyConfig.ProxyBypass)!;

if (NetEventSource.IsEnabled)
{
Expand Down Expand Up @@ -59,7 +60,7 @@ public WinInetProxyHelper()
}
}

public string AutoConfigUrl => _autoConfigUrl;
public string? AutoConfigUrl => _autoConfigUrl;

public bool AutoDetect => _autoDetect;

Expand All @@ -69,16 +70,16 @@ public WinInetProxyHelper()

public bool ManualSettingsOnly => !AutoSettingsUsed && ManualSettingsUsed;

public string Proxy => _proxy;
public string? Proxy => _proxy;

public string ProxyBypass => _proxyBypass;
public string? ProxyBypass => _proxyBypass;

public bool RecentAutoDetectionFailure =>
_autoDetectionFailed &&
Environment.TickCount - _lastTimeAutoDetectionFailed <= RecentAutoDetectionInterval;

public bool GetProxyForUrl(
SafeWinHttpHandle sessionHandle,
SafeWinHttpHandle? sessionHandle,
Uri uri,
out Interop.WinHttp.WINHTTP_PROXY_INFO proxyInfo)
{
Expand Down Expand Up @@ -123,7 +124,7 @@ public bool GetProxyForUrl(
{
_autoDetectionFailed = false;
if (Interop.WinHttp.WinHttpGetProxyForUrl(
sessionHandle,
sessionHandle!,
uri.AbsoluteUri,
ref autoProxyOptions,
out proxyInfo))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Buffers;
using System.Diagnostics;
#if KESTREL
Expand Down Expand Up @@ -93,7 +94,7 @@ private enum State : byte
private byte[] _headerValueOctets;

private State _state = State.Ready;
private byte[] _headerName;
private byte[]? _headerName;
private int _stringIndex;
private int _stringLength;
private int _headerNameLength;
Expand Down Expand Up @@ -129,13 +130,13 @@ public void Decode(in ReadOnlySequence<byte> data, bool endHeaders, IHttpHeaders
CheckIncompleteHeaderBlock(endHeaders);
}

public void Decode(ReadOnlySpan<byte> data, bool endHeaders, IHttpHeadersHandler handler)
public void Decode(ReadOnlySpan<byte> data, bool endHeaders, IHttpHeadersHandler? handler)
{
DecodeInternal(data, endHeaders, handler);
CheckIncompleteHeaderBlock(endHeaders);
}

private void DecodeInternal(ReadOnlySpan<byte> data, bool endHeaders, IHttpHeadersHandler handler)
private void DecodeInternal(ReadOnlySpan<byte> data, bool endHeaders, IHttpHeadersHandler? handler)
{
int intResult;

Expand Down Expand Up @@ -370,7 +371,7 @@ private void CheckIncompleteHeaderBlock(bool endHeaders)
}
}

private void ProcessHeaderValue(IHttpHeadersHandler handler)
private void ProcessHeaderValue(IHttpHeadersHandler? handler)
{
OnString(nextState: State.Ready);

Expand All @@ -394,7 +395,7 @@ public void CompleteDecode()
}
}

private void OnIndexedHeaderField(int index, IHttpHeadersHandler handler)
private void OnIndexedHeaderField(int index, IHttpHeadersHandler? handler)
{
HeaderField header = GetHeader(index);
handler?.OnHeader(header.Name, header.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Collections.Generic;
using System.Diagnostics;

namespace System.Net.Http.HPack
Expand Down Expand Up @@ -370,7 +372,7 @@ public static bool EncodeStringLiteral(string value, Span<byte> destination, out
return false;
}

public static bool EncodeStringLiterals(ReadOnlySpan<string> values, string separator, Span<byte> destination, out int bytesWritten)
public static bool EncodeStringLiterals(ReadOnlySpan<string> values, string? separator, Span<byte> destination, out int bytesWritten)
{
bytesWritten = 0;

Expand All @@ -393,6 +395,7 @@ public static bool EncodeStringLiterals(ReadOnlySpan<string> values, string sepa
valueLength = checked((int)(valueLength + part.Length));
}

Debug.Assert(separator != null);
valueLength = checked((int)(valueLength + (values.Length - 1) * separator.Length));

destination[0] = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Buffers;
using System.Diagnostics;
using System.Net.Http.HPack;
Expand Down Expand Up @@ -118,7 +119,7 @@ private enum State
private bool _huffman;
private int? _index;

private byte[] _headerName;
private byte[]? _headerName;
private int _headerNameLength;
private int _headerValueLength;
private int _stringLength;
Expand All @@ -130,7 +131,7 @@ private enum State
private static void ReturnAndGetNewPooledArray(ref byte[] buffer, int newSize)
{
byte[] old = buffer;
buffer = null;
buffer = null!;

Pool.Return(old, clearArray: true);
buffer = Pool.Rent(newSize);
Expand All @@ -151,19 +152,19 @@ public void Dispose()
if (_stringOctets != null)
{
Pool.Return(_stringOctets, true);
_stringOctets = null;
_stringOctets = null!;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder the pattern. If it is important why doesn't Pool.Return() assign the null?

}

if (_headerNameOctets != null)
{
Pool.Return(_headerNameOctets, true);
_headerNameOctets = null;
_headerNameOctets = null!;
}

if (_headerValueOctets != null)
{
Pool.Return(_headerValueOctets, true);
_headerValueOctets = null;
_headerValueOctets = null!;
}
}

Expand Down
Loading