Skip to content

Commit 9ee1543

Browse files
committed
allow wss:// scheme, preserve uri query parameters
1 parent d63b1d5 commit 9ee1543

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/GraphQL.Client/GraphQLHttpClient.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public GraphQLHttpClient(GraphQLHttpClientOptions options, IGraphQLWebsocketJson
6666
HttpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version.ToString()));
6767

6868
_lazyHttpWebSocket = new Lazy<GraphQLHttpWebSocket>(() => new GraphQLHttpWebSocket(GetWebSocketUri(), this));
69+
if ((Options.EndPoint?.Scheme == "wss") || (Options.EndPoint?.Scheme == "ws"))
70+
{
71+
Options.UseWebSocketForQueriesAndMutations = true;
72+
}
6973
}
7074

7175
#endregion
@@ -155,8 +159,12 @@ private async Task<GraphQLHttpResponse<TResponse>> SendHttpRequestAsync<TRespons
155159

156160
private Uri GetWebSocketUri()
157161
{
158-
string webSocketSchema = Options.EndPoint.Scheme == "https" ? "wss" : "ws";
159-
return new Uri($"{webSocketSchema}://{Options.EndPoint.Host}:{Options.EndPoint.Port}{Options.EndPoint.AbsolutePath}");
162+
string webSocketSchema = Options.EndPoint.Scheme == "https"
163+
? "wss"
164+
: Options.EndPoint.Scheme == "http"
165+
? "ws"
166+
: Options.EndPoint.Scheme;
167+
return new Uri($"{webSocketSchema}://{Options.EndPoint.Host}:{Options.EndPoint.Port}{Options.EndPoint.AbsolutePath}{Options.EndPoint.Query}");
160168
}
161169

162170
#endregion

0 commit comments

Comments
 (0)