Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit db2e120

Browse files
committed
Add GetContentLength() ext method
1 parent b8ac3c4 commit db2e120

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/ServiceStack.Text/HttpUtils.HttpClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,9 @@ public static class HttpClientExt
11221122
{
11231123
public static bool MatchesContentType(this HttpResponseMessage res, string matchesContentType) =>
11241124
MimeTypes.MatchesContentType(res.GetHeader(HttpHeaders.ContentType), matchesContentType);
1125+
1126+
public static long? GetContentLength(this HttpResponseMessage res) =>
1127+
res.Content.Headers.ContentLength;
11251128
}
11261129

11271130
#endif

src/ServiceStack.Text/HttpUtils.WebRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,5 +1186,8 @@ public static class HttpClientExt
11861186
{
11871187
public static bool MatchesContentType(this HttpWebResponse res, string matchesContentType) =>
11881188
MimeTypes.MatchesContentType(res.Headers[HttpHeaders.ContentType], matchesContentType);
1189+
1190+
public static long? GetContentLength(this HttpWebResponse res) =>
1191+
res.ContentLength == -1 ? null : res.ContentLength;
11891192
}
11901193
#endif

0 commit comments

Comments
 (0)