Skip to content

Commit

Permalink
revert httpcontext changes
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Oct 25, 2024
1 parent d9fe85e commit acf420a
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 60 deletions.
6 changes: 3 additions & 3 deletions src/Speckle.Sdk/Api/GraphQL/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public sealed class Client : ISpeckleGraphQLClient, IDisposable
[JsonIgnore]
public Account Account { get; }

private System.Net.Http.HttpClient HttpClient { get; }
private HttpClient HttpClient { get; }

public GraphQLHttpClient GQLClient { get; }

Expand Down Expand Up @@ -293,7 +293,7 @@ internal IDisposable SubscribeTo<T>(GraphQLRequest request, Action<object, T> ca
}
}

private static GraphQLHttpClient CreateGraphQLClient(Account account, System.Net.Http.HttpClient httpClient)
private static GraphQLHttpClient CreateGraphQLClient(Account account, HttpClient httpClient)
{
var gQLClient = new GraphQLHttpClient(
new GraphQLHttpClientOptions
Expand Down Expand Up @@ -328,7 +328,7 @@ private static GraphQLHttpClient CreateGraphQLClient(Account account, System.Net
return gQLClient;
}

private static System.Net.Http.HttpClient CreateHttpClient(ISpeckleApplication application, ISpeckleHttp speckleHttp, Account account)
private static HttpClient CreateHttpClient(ISpeckleApplication application, ISpeckleHttp speckleHttp, Account account)
{
var httpClient = speckleHttp.CreateHttpClient(timeoutSeconds: 30, authorizationToken: account.token);

Expand Down
10 changes: 5 additions & 5 deletions src/Speckle.Sdk/Common/HashCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static HashCode OfEach<T>(IEnumerable<T>? items) =>
/// <typeparam name="T">The type of the item.</typeparam>
/// <param name="item">The item.</param>
/// <returns>The new hash code.</returns>
public HashCode And<T>(T item) => new HashCode(CombineHashCodes(this._value, GetHashCode(item)));
public HashCode And<T>(T item) => new HashCode(CombineHashCodes(_value, GetHashCode(item)));

/// <summary>
/// Adds the hash code of the specified items in the collection.
Expand All @@ -75,21 +75,21 @@ public HashCode AndEach<T>(IEnumerable<T>? items)
{
if (items == null)
{
return new HashCode(this._value);
return new HashCode(_value);
}

return new HashCode(GetHashCode(items, this._value));
return new HashCode(GetHashCode(items, _value));
}

/// <inheritdoc />
public bool Equals(HashCode other) => this._value.Equals(other._value);
public bool Equals(HashCode other) => _value.Equals(other._value);

/// <inheritdoc />
public override bool Equals(object? obj)
{
if (obj is HashCode code)
{
return this.Equals(code);
return Equals(code);
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions src/Speckle.Sdk/Credentials/AccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ private async Task<TokenExchangeResponse> GetToken(string accessCode, string cha
challenge,
};

using var content = new System.Net.Http.StringContent(JsonConvert.SerializeObject(body));
using var content = new StringContent(JsonConvert.SerializeObject(body));
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await client.PostAsync(new Uri(server, "/auth/token"), content).ConfigureAwait(false);

Expand All @@ -787,7 +787,7 @@ private async Task<TokenExchangeResponse> GetRefreshedToken(string refreshToken,
refreshToken,
};

using var content = new System.Net.Http.StringContent(JsonConvert.SerializeObject(body));
using var content = new StringContent(JsonConvert.SerializeObject(body));
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await client.PostAsync(new Uri(server, "/auth/token"), content).ConfigureAwait(false);

Expand Down
16 changes: 8 additions & 8 deletions src/Speckle.Sdk/Helpers/Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ public class SpeckleHttp(ILogger<SpeckleHttp> logger, ISpeckleHttpClientHandlerF
/// </summary>
/// <param name="uri">The URI that should be pinged</param>
/// <exception cref="System.Net.Http.HttpRequestException">Request to <paramref name="uri"/> failed</exception>
public async Task<System.Net.Http.HttpResponseMessage> HttpPing(Uri uri)
public async Task<HttpResponseMessage> HttpPing(Uri uri)
{
try
{
using var httpClient = CreateHttpClient();
System.Net.Http.HttpResponseMessage response = await httpClient.GetAsync(uri).ConfigureAwait(false);
HttpResponseMessage response = await httpClient.GetAsync(uri).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
logger.LogInformation("Successfully pinged {uri}", uri);
return response;
}
catch (System.Net.Http.HttpRequestException ex)
catch (HttpRequestException ex)
{
logger.LogWarning(ex, "Ping to {uri} was unsuccessful: {message}", uri, ex.Message);
throw new System.Net.Http.HttpRequestException($"Ping to {uri} was unsuccessful", ex);
throw new HttpRequestException($"Ping to {uri} was unsuccessful", ex);
}
}

public const int DEFAULT_TIMEOUT_SECONDS = 60;

public System.Net.Http.HttpClient CreateHttpClient(
System.Net.Http.HttpMessageHandler? innerHandler = null,
public HttpClient CreateHttpClient(
HttpMessageHandler? innerHandler = null,
int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS,
string? authorizationToken = null
)
Expand All @@ -44,7 +44,7 @@ public System.Net.Http.HttpClient CreateHttpClient(

var speckleHandler = speckleHttpClientHandlerFactory.Create(innerHandler, timeoutSeconds);

var client = new System.Net.Http.HttpClient(speckleHandler)
var client = new HttpClient(speckleHandler)
{
Timeout =
Timeout.InfiniteTimeSpan //timeout is configured on the SpeckleHttpClientHandler through policy
Expand All @@ -68,7 +68,7 @@ public static bool CanAddAuth(string? authToken, out string? bearerHeader)
return false;
}

private static void AddAuthHeader(System.Net.Http.HttpClient client, string? authToken)
private static void AddAuthHeader(HttpClient client, string? authToken)
{
if (CanAddAuth(authToken, out string? value))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Speckle.Sdk/Models/GraphTraversal/RuleBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private TraversalRule()

public ITraversalBuilderReturn ContinueTraversing(SelectMembers membersToTraverse)
{
this._membersToTraverse = membersToTraverse;
_membersToTraverse = membersToTraverse;
return this;
}

Expand Down
22 changes: 11 additions & 11 deletions src/Speckle.Sdk/Serialisation/V2/ServerObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ServerObjectManager : IServerObjectManager
private static readonly char[] s_separator = { '\t' };

private readonly ISdkActivityFactory _activityFactory;
private readonly System.Net.Http.HttpClient _client;
private readonly HttpClient _client;

public ServerObjectManager(
ISpeckleHttp speckleHttp,
Expand All @@ -27,7 +27,7 @@ public ServerObjectManager(
{
_activityFactory = activityFactory;
_client = speckleHttp.CreateHttpClient(
new System.Net.Http.HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip },
new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip },
timeoutSeconds: timeoutSeconds,
authorizationToken: authorizationToken
);
Expand All @@ -44,18 +44,18 @@ [EnumeratorCancellation] CancellationToken cancellationToken
using var _ = _activityFactory.Start();
cancellationToken.ThrowIfCancellationRequested();

using var childrenHttpMessage = new System.Net.Http.HttpRequestMessage
using var childrenHttpMessage = new HttpRequestMessage
{
RequestUri = new Uri($"/api/getobjects/{streamId}", UriKind.Relative),
Method = System.Net.Http.HttpMethod.Post,
Method = HttpMethod.Post,
};

Dictionary<string, string> postParameters = new() { { "objects", JsonConvert.SerializeObject(objectIds) } };
string serializedPayload = JsonConvert.SerializeObject(postParameters);
childrenHttpMessage.Content = new System.Net.Http.StringContent(serializedPayload, Encoding.UTF8, "application/json");
childrenHttpMessage.Content = new StringContent(serializedPayload, Encoding.UTF8, "application/json");
childrenHttpMessage.Headers.Add("Accept", "text/plain");

System.Net.Http.HttpResponseMessage childrenHttpResponse = await _client
HttpResponseMessage childrenHttpResponse = await _client
.SendAsync(childrenHttpMessage, cancellationToken)
.ConfigureAwait(false);

Expand All @@ -79,14 +79,14 @@ CancellationToken cancellationToken
cancellationToken.ThrowIfCancellationRequested();

// Get root object
using var rootHttpMessage = new System.Net.Http.HttpRequestMessage
using var rootHttpMessage = new HttpRequestMessage
{
RequestUri = new Uri($"/objects/{streamId}/{objectId}/single", UriKind.Relative),
Method = System.Net.Http.HttpMethod.Get,
Method = HttpMethod.Get,
};

System.Net.Http.HttpResponseMessage rootHttpResponse = await _client
.SendAsync(rootHttpMessage, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken)
HttpResponseMessage rootHttpResponse = await _client
.SendAsync(rootHttpMessage, HttpCompletionOption.ResponseContentRead, cancellationToken)
.ConfigureAwait(false);

var (_, json) = await ResponseProgress(rootHttpResponse, progress, true, cancellationToken)
Expand All @@ -96,7 +96,7 @@ CancellationToken cancellationToken
}

private async IAsyncEnumerable<(string?, string)> ResponseProgress(
System.Net.Http.HttpResponseMessage childrenHttpResponse,
HttpResponseMessage childrenHttpResponse,
IProgress<ProgressArgs>? progress,
bool isSingle,
[EnumeratorCancellation] CancellationToken cancellationToken
Expand Down
8 changes: 4 additions & 4 deletions src/Speckle.Sdk/Transports/ServerUtils/GzipContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ namespace Speckle.Sdk.Transports.ServerUtils;
/// <remarks>
/// https://cymbeline.ch/2014/03/16/gzip-encoding-an-http-post-request-body/
/// </remarks>
internal sealed class GzipContent : System.Net.Http.HttpContent
internal sealed class GzipContent : HttpContent
{
private readonly System.Net.Http.HttpContent? _content;
private readonly HttpContent? _content;

public GzipContent(System.Net.Http.HttpContent? content)
public GzipContent(HttpContent? content)
{
_content = content;

Expand Down Expand Up @@ -38,7 +38,7 @@ protected override async Task SerializeToStreamAsync(Stream stream, TransportCon
}
else
{
using var emptyContent = new System.Net.Http.StringContent(string.Empty);
using var emptyContent = new StringContent(string.Empty);
await emptyContent.CopyToAsync(gzip).ConfigureAwait(false);
}
await gzip.FlushAsync().ConfigureAwait(false);
Expand Down
6 changes: 3 additions & 3 deletions src/Speckle.Sdk/Transports/ServerUtils/ProgressContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Speckle.Sdk.Transports.ServerUtils;

internal class ProgressContent : System.Net.Http.HttpContent
internal class ProgressContent : HttpContent
{
private readonly System.Net.Http.HttpContent _innerContent;
private readonly HttpContent _innerContent;
private readonly IProgress<ProgressArgs>? _progress;

public ProgressContent(System.Net.Http.HttpContent innerContent, IProgress<ProgressArgs>? progress)
public ProgressContent(HttpContent innerContent, IProgress<ProgressArgs>? progress)
{
_innerContent = innerContent;
_progress = progress;
Expand Down
Loading

0 comments on commit acf420a

Please sign in to comment.