Skip to content

Commit f2dee02

Browse files
committed
Throw in case of an invalid encoding
1 parent 486be15 commit f2dee02

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/AngleSharp/Io/DefaultHttpRequester.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private void SendRequest(Stream target)
184184
[return: NotNullIfNotNull("response")]
185185
private DefaultResponse? GetResponse(HttpWebResponse? response)
186186
{
187-
if (response != null)
187+
if (response is not null)
188188
{
189189
var originalCookies = _cookies.GetCookies(_request.Address!);
190190
var newCookies = _cookies.GetCookies(response.ResponseUri);
@@ -200,6 +200,19 @@ private void SendRequest(Stream target)
200200
foreach (var header in headers)
201201
{
202202
result.Headers.Add(header.Key, header.Value);
203+
204+
if (header.Key.Isi(HeaderNames.ContentEncoding))
205+
{
206+
switch (header.Value)
207+
{
208+
case "":
209+
case "gzip":
210+
case "deflate":
211+
break;
212+
default:
213+
throw new InvalidOperationException($"The given server response is invalid. The encoding '{header.Value}' is not supported.");
214+
}
215+
}
203216
}
204217

205218
if (cookies.Length > 0)

0 commit comments

Comments
 (0)