Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser][wasm] Configuring request options in Browser WebAssembly #39182

Merged
merged 20 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f47ccd3
[browser][wasm] Initial addition of configuring request options in Br…
kjpou1 Jul 13, 2020
29a208e
Fix key code. Not what was proposed
kjpou1 Jul 13, 2020
64e8227
Add TryGetValue<TValue> and Set<TValue> as per proposal
kjpou1 Jul 14, 2020
23f0207
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jul 14, 2020
b0e55ee
Add missing obsolete attribute
kjpou1 Jul 14, 2020
d22d482
Address review comments
kjpou1 Jul 14, 2020
4739203
Update tests to use Options and not obsolete Properties.
kjpou1 Jul 14, 2020
7101065
Implement IDictionary<string, object?> explicitly
kjpou1 Jul 15, 2020
1056cdc
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jul 15, 2020
8886161
Update tests to use Options and not obsolete Properties.
kjpou1 Jul 15, 2020
f62bc16
Add HttpRequestOptions source to the System.Net.Http.Unit.Tests proje…
kjpou1 Jul 15, 2020
44929fd
Address review comments - explicit
kjpou1 Jul 15, 2020
478bca6
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jul 15, 2020
8098c0e
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jul 16, 2020
3d5d7fa
Fix build error cannot convert from 'string' to 'System.Net.Http.Http…
kjpou1 Jul 16, 2020
7398927
Add tests for HttpRequestOptions
kjpou1 Jul 16, 2020
ea78e61
Fix test build
kjpou1 Jul 16, 2020
d6b49c5
Add special case code for NETFRAMEWORK for API change.
kjpou1 Jul 17, 2020
1b5683e
#endif out of place fix
kjpou1 Jul 17, 2020
23f1bc8
#endif out of place fix
kjpou1 Jul 17, 2020
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
10 changes: 10 additions & 0 deletions src/libraries/System.Net.Http/ref/System.Net.Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,22 @@ public HttpRequestMessage(System.Net.Http.HttpMethod method, System.Uri? request
public System.Net.Http.Headers.HttpRequestHeaders Headers { get { throw null; } }
public System.Net.Http.HttpMethod Method { get { throw null; } set { } }
public System.Collections.Generic.IDictionary<string, object?> Properties { get { throw null; } }
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
public HttpRequestOptions Options { get { throw null; } }
public System.Uri? RequestUri { get { throw null; } set { } }
public System.Version Version { get { throw null; } set { } }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
public override string ToString() { throw null; }
}

public readonly struct HttpRequestOptionsKey<TKey>
{
public HttpRequestOptionsKey(TKey key) {}
public TKey Key { get { throw null; } }
}
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved

public sealed class HttpRequestOptions : System.Collections.Generic.Dictionary<HttpRequestOptionsKey<string>, object> { }
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved

public partial class HttpResponseMessage : System.IDisposable
{
public HttpResponseMessage() { }
Expand Down
4 changes: 3 additions & 1 deletion src/libraries/System.Net.Http/src/System.Net.Http.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<AssemblyName>System.Net.Http</AssemblyName>
Expand Down Expand Up @@ -47,6 +47,8 @@
<Compile Include="System\Net\Http\HttpParseResult.cs" />
<Compile Include="System\Net\Http\HttpRequestException.cs" />
<Compile Include="System\Net\Http\HttpRequestMessage.cs" />
<Compile Include="System\Net\Http\HttpRequestOptions.cs" />
<Compile Include="System\Net\Http\HttpRequestOptionsKey.cs" />
<Compile Include="System\Net\Http\HttpResponseMessage.cs" />
<Compile Include="System\Net\Http\HttpRuleParser.cs" />
<Compile Include="System\Net\Http\HttpTelemetry.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected internal override async Task<HttpResponseMessage> SendAsync(HttpReques
{
var requestObject = new JSObject();

if (request.Properties.TryGetValue("WebAssemblyFetchOptions", out object? fetchOptionsValue) &&
if (request.Options.TryGetValue(new HttpRequestOptionsKey<string>("WebAssemblyFetchOptions"), out object? fetchOptionsValue) &&
fetchOptionsValue is IDictionary<string, object> fetchOptions)
{
foreach (KeyValuePair<string, object> item in fetchOptions)
Expand Down Expand Up @@ -221,7 +221,7 @@ protected internal override async Task<HttpResponseMessage> SendAsync(HttpReques

HttpResponseMessage httpResponse = new HttpResponseMessage((HttpStatusCode)status.Status);

bool streamingEnabled = request.Properties.TryGetValue("WebAssemblyEnableStreamingResponse", out object? streamingEnabledValue) && (bool)(streamingEnabledValue ?? false);
bool streamingEnabled = request.Options.TryGetValue(new HttpRequestOptionsKey<string>("WebAssemblyEnableStreamingResponse"), out object? streamingEnabledValue) && (bool)(streamingEnabledValue ?? false);

httpResponse.Content = StreamingSupported && streamingEnabled
? new StreamContent(wasmHttpReadStream = new WasmHttpReadStream(status))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class HttpRequestMessage : IDisposable
private HttpContent? _content;
private bool _disposed;
private IDictionary<string, object?>? _properties;
private HttpRequestOptions? _options;

public Version Version
{
Expand Down Expand Up @@ -111,6 +112,7 @@ public HttpRequestHeaders Headers

internal bool HasHeaders => _headers != null;

[Obsolete("Use Options instead.")]
public IDictionary<string, object?> Properties
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
{
get
Expand All @@ -123,6 +125,18 @@ public HttpRequestHeaders Headers
}
}

public HttpRequestOptions Options
{
get
{
if (_options == null)
{
_options = new HttpRequestOptions();
}
return _options;
}
}
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved

public HttpRequestMessage()
: this(HttpMethod.Get, (Uri?)null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;

namespace System.Net.Http
{
public sealed class HttpRequestOptions : Dictionary<HttpRequestOptionsKey<string>, object?> { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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<TKey>
{
private readonly TKey _key;
public HttpRequestOptionsKey(TKey key)
{
_key = key;
}
public TKey Key => _key;
}
}