Skip to content

Commit d379d85

Browse files
author
Raul Hidalgo Caballero
authored
WSS in case of HTTPS (#67)
* force secure mode * .
1 parent 9f97efc commit d379d85

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

src/GraphQL.Client/Http/GraphQLHttpClient.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ public GraphQLHttpClient(GraphQLHttpClientOptions options) {
9090
this.graphQLHttpHandler = new GraphQLHttpHandler(options);
9191
}
9292

93-
internal GraphQLHttpClient(GraphQLHttpClientOptions options,HttpClient httpClient) {
93+
internal GraphQLHttpClient(GraphQLHttpClientOptions options, HttpClient httpClient) {
9494
if (options == null) { throw new ArgumentNullException(nameof(options)); }
9595
if (options.EndPoint == null) { throw new ArgumentNullException(nameof(options.EndPoint)); }
9696
if (options.JsonSerializerSettings == null) { throw new ArgumentNullException(nameof(options.JsonSerializerSettings)); }
9797
if (options.HttpMessageHandler == null) { throw new ArgumentNullException(nameof(options.HttpMessageHandler)); }
9898
if (options.MediaType == null) { throw new ArgumentNullException(nameof(options.MediaType)); }
9999

100-
this.graphQLHttpHandler = new GraphQLHttpHandler(options,httpClient);
100+
this.graphQLHttpHandler = new GraphQLHttpHandler(options, httpClient);
101101
}
102102

103103
public Task<GraphQLResponse> SendQueryAsync(string query, CancellationToken cancellationToken = default) =>
@@ -121,7 +121,8 @@ public Task<IGraphQLSubscriptionResult> SendSubscribeAsync(GraphQLRequest reques
121121
if (request == null) { throw new ArgumentNullException(nameof(request)); }
122122
if (request.Query == null) { throw new ArgumentNullException(nameof(request.Query)); }
123123

124-
var webSocketUri = new Uri($"ws://{this.EndPoint.Host}:{this.EndPoint.Port}{this.EndPoint.AbsolutePath}");
124+
var webSocketSchema = this.EndPoint.Scheme == "https" ? "wss" : "ws";
125+
var webSocketUri = new Uri($"{webSocketSchema}://{this.EndPoint.Host}:{this.EndPoint.Port}{this.EndPoint.AbsolutePath}");
125126
var graphQLSubscriptionResult = new GraphQLHttpSubscriptionResult(webSocketUri, request);
126127
graphQLSubscriptionResult.StartAsync(cancellationToken);
127128
return Task.FromResult((IGraphQLSubscriptionResult)graphQLSubscriptionResult);

src/GraphQL.Client/Http/GraphQLHttpSubscriptionResult.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private Task SendInitialMessageAsync(CancellationToken cancellationToken = defau
6161
}
6262

6363
private static class GQLWebSocketMessageType {
64+
6465
/// <summary>
6566
/// Client sends this message after plain websocket connection to start the communication with the server
6667
/// The server will response only with GQL_CONNECTION_ACK + GQL_CONNECTION_KEEP_ALIVE(if used) or GQL_CONNECTION_ERROR
@@ -142,6 +143,7 @@ private static class GQLWebSocketMessageType {
142143
/// id: string : operation id
143144
/// </summary>
144145
public const string GQL_STOP = "stop"; // Client -> Server
146+
145147
}
146148

147149
}

src/GraphQL.Client/Http/Internal/GraphQLHttpHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public async Task<GraphQLResponse> ReadHttpResponseMessageAsync(HttpResponseMess
8787
};
8888
try {
8989
return jsonSerializer.Deserialize<GraphQLResponse>(jsonTextReader);
90-
} catch (JsonReaderException exception) {
90+
}
91+
catch (JsonReaderException exception) {
9192
if (httpResponseMessage.IsSuccessStatusCode) {
9293
throw exception;
9394
}

src/GraphQL.Client/Obsolete.GraphQLClient.Extensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace GraphQL.Client {
99
/// <summary>
1010
/// Extension Methods for <see cref="GraphQLClient"/>
1111
/// </summary>
12-
[Obsolete()]
12+
[Obsolete]
1313
public static class GraphQLClientExtensions {
1414

1515
private const string IntrospectionQuery = @"

0 commit comments

Comments
 (0)