forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[browser][wasm] Configuring request options in Browser WebAssembly (d…
…otnet#39182) * [browser][wasm] Initial addition of configuring request options in Browser WebAssembly * Fix key code. Not what was proposed * Add TryGetValue<TValue> and Set<TValue> as per proposal * Add missing obsolete attribute * Address review comments * Update tests to use Options and not obsolete Properties. * Implement IDictionary<string, object?> explicitly * Update tests to use Options and not obsolete Properties. * Add HttpRequestOptions source to the System.Net.Http.Unit.Tests project to fix build. * Address review comments - explicit * Fix build error cannot convert from 'string' to 'System.Net.Http.HttpRequestOptionsKey<object>' * Add tests for HttpRequestOptions * Fix test build * Add special case code for NETFRAMEWORK for API change. * #endif out of place fix * #endif out of place fix
- Loading branch information
1 parent
86088b2
commit 1997332
Showing
11 changed files
with
591 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/libraries/System.Net.Http/src/System/Net/Http/HttpRequestOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace System.Net.Http | ||
{ | ||
public sealed class HttpRequestOptions : IDictionary<string, object?> | ||
{ | ||
private Dictionary<string, object?> Options { get; } = new Dictionary<string, object?>(); | ||
object? IDictionary<string, object?>.this[string key] | ||
{ | ||
get | ||
{ | ||
return Options[key]; | ||
} | ||
set | ||
{ | ||
Options[key] = value; | ||
} | ||
} | ||
ICollection<string> IDictionary<string, object?>.Keys => Options.Keys; | ||
ICollection<object?> IDictionary<string, object?>.Values => Options.Values; | ||
int ICollection<KeyValuePair<string, object?>>.Count => Options.Count; | ||
bool ICollection<KeyValuePair<string, object?>>.IsReadOnly => ((IDictionary<string, object?>)Options).IsReadOnly; | ||
void IDictionary<string, object?>.Add(string key, object? value) => Options.Add(key, value); | ||
void ICollection<KeyValuePair<string, object?>>.Add(KeyValuePair<string, object?> item) => ((IDictionary<string, object?>)Options).Add(item); | ||
void ICollection<KeyValuePair<string, object?>>.Clear() => Options.Clear(); | ||
bool ICollection<KeyValuePair<string, object?>>.Contains(KeyValuePair<string, object?> item) => ((IDictionary<string, object?>)Options).Contains(item); | ||
bool IDictionary<string, object?>.ContainsKey(string key) => Options.ContainsKey(key); | ||
void ICollection<KeyValuePair<string, object?>>.CopyTo(KeyValuePair<string, object?>[] array, int arrayIndex) => | ||
((IDictionary<string, object?>)Options).CopyTo(array, arrayIndex); | ||
IEnumerator<KeyValuePair<string, object?>> IEnumerable<KeyValuePair<string, object?>>.GetEnumerator() => Options.GetEnumerator(); | ||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => ((System.Collections.IEnumerable)Options).GetEnumerator(); | ||
bool IDictionary<string, object?>.Remove(string key) => Options.Remove(key); | ||
bool ICollection<KeyValuePair<string, object?>>.Remove(KeyValuePair<string, object?> item) => ((IDictionary<string, object?>)Options).Remove(item); | ||
bool IDictionary<string, object?>.TryGetValue(string key, out object? value) => Options.TryGetValue(key, out value); | ||
public bool TryGetValue<TValue>(HttpRequestOptionsKey<TValue> key, [MaybeNullWhen(false)] out TValue value) | ||
{ | ||
if (Options.TryGetValue(key.Key, out object? _value) && _value is TValue tvalue) | ||
{ | ||
value = tvalue; | ||
return true; | ||
} | ||
|
||
value = default(TValue); | ||
return false; | ||
} | ||
|
||
public void Set<TValue>(HttpRequestOptionsKey<TValue> key, TValue value) | ||
{ | ||
Options[key.Key] = value; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/libraries/System.Net.Http/src/System/Net/Http/HttpRequestOptionsKey.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
|
||
namespace System.Net.Http | ||
{ | ||
public readonly struct HttpRequestOptionsKey<TValue> | ||
{ | ||
public string Key { get; } | ||
public HttpRequestOptionsKey(string key) | ||
{ | ||
Key = key; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.