Skip to content

Commit 5dc3b8b

Browse files
committed
Some cosmetics
1 parent cfe19a9 commit 5dc3b8b

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

AngleSharp.Io/Dom/WebSocket.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,23 @@ public WebSocket(IWindow window, String url, params String[] protocols)
102102
_window = window;
103103

104104
if (_url.IsInvalid || _url.IsRelative)
105+
{
105106
throw new DomException(DomError.Syntax);
107+
}
106108

107109
var invalid = protocols.Length - protocols.Distinct().Where(IsValid).Count();
108110

109111
if (invalid > 0)
112+
{
110113
throw new DomException(DomError.Syntax);
114+
}
111115

112116
_ws = new ClientWebSocket();
113117

114118
foreach (var protocol in protocols)
119+
{
115120
_ws.Options.AddSubProtocol(protocol);
121+
}
116122

117123
_ws.Options.KeepAliveInterval = TimeSpan.FromSeconds(20);
118124
ConnectAsync(url).Forget();
@@ -221,10 +227,12 @@ void IDisposable.Dispose()
221227

222228
static Boolean IsValid(String protocol)
223229
{
224-
for (int i = 0; i < protocol.Length; i++)
230+
for (var i = 0; i < protocol.Length; i++)
225231
{
226232
if (protocol[i] < 0x21 || protocol[i] > 0x7e)
233+
{
227234
return false;
235+
}
228236
}
229237

230238
return true;
@@ -237,7 +245,9 @@ async Task SendAsync(String message)
237245
var messagesCount = Math.DivRem(messageBuffer.Length, SendChunkSize, out remainder);
238246

239247
if (remainder > 0)
248+
{
240249
messagesCount++;
250+
}
241251

242252
remainder = messageBuffer.Length;
243253

AngleSharp.Io/Network/HttpClientRequester.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public HttpClientRequester(HttpClient client)
5555
/// </returns>
5656
public Boolean SupportsProtocol(String protocol)
5757
{
58-
return protocol.Equals("http", StringComparison.OrdinalIgnoreCase) ||
59-
protocol.Equals("https", StringComparison.OrdinalIgnoreCase);
58+
return protocol.Equals(ProtocolNames.Http, StringComparison.OrdinalIgnoreCase) ||
59+
protocol.Equals(ProtocolNames.Https, StringComparison.OrdinalIgnoreCase);
6060
}
6161

6262
/// <summary>
@@ -79,7 +79,9 @@ public async Task<IResponse> RequestAsync(IRequest request, CancellationToken ca
7979
// Source:
8080
// https://github.com/aspnet/Mvc/blob/02c36a1c4824936682b26b6c133d11bebee822a2/src/Microsoft.AspNet.Mvc.WebApiCompatShim/HttpRequestMessage/HttpRequestMessageFeature.cs
8181
if (!requestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value))
82+
{
8283
contentHeaders.Add(new KeyValuePair<String, String>(header.Key, header.Value));
84+
}
8385
}
8486

8587
// set up the content
@@ -88,7 +90,9 @@ public async Task<IResponse> RequestAsync(IRequest request, CancellationToken ca
8890
requestMessage.Content = new StreamContent(request.Content);
8991

9092
foreach (var header in contentHeaders)
93+
{
9194
requestMessage.Content.Headers.TryAddWithoutValidation(header.Key, header.Value);
95+
}
9296
}
9397

9498
// execute the request
@@ -102,12 +106,17 @@ public async Task<IResponse> RequestAsync(IRequest request, CancellationToken ca
102106
StatusCode = responseMessage.StatusCode
103107
};
104108

105-
if (responseMessage.Content != null)
109+
// get the anticipated content
110+
var content = responseMessage.Content;
111+
112+
if (content != null)
106113
{
107-
response.Content = await responseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false);
114+
response.Content = await content.ReadAsStreamAsync().ConfigureAwait(false);
108115

109-
foreach (var pair in responseMessage.Content.Headers)
116+
foreach (var pair in content.Headers)
117+
{
110118
response.Headers[pair.Key] = String.Join(", ", pair.Value);
119+
}
111120
}
112121

113122
return response;

0 commit comments

Comments
 (0)