Skip to content

Commit 7083b7e

Browse files
committed
Send back headers received from server
1 parent 698d390 commit 7083b7e

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

LessAnnoyingHttp/Http.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public static Response Get(string endpoint, Header[]? headers = null) {
3434
throw new TimeoutException($"Timeout waiting for response for request to {endpoint}");
3535
} catch (Exception e) {
3636
return new Response { IsSuccessful = false, Body = "", Exception = e };
37-
}
38-
39-
return new Response { IsSuccessful = response.IsSuccessStatusCode, Body = response.Content.ReadAsStringAsync().Result, StatusCode = response.StatusCode };
37+
}
38+
39+
return new Response { IsSuccessful = response.IsSuccessStatusCode, Body = response.Content.ReadAsStringAsync().Result, Headers = response.Headers.ToDictionary(), StatusCode = response.StatusCode };
4040
}
4141

4242
private static Response BodyRequest(string endpoint, HttpMethod method, string body, Header[]? headers, string contentType) {
@@ -61,7 +61,7 @@ private static Response BodyRequest(string endpoint, HttpMethod method, string b
6161
return new Response { IsSuccessful = false, Body = "", Exception = e };
6262
}
6363

64-
return new Response { IsSuccessful = response.IsSuccessStatusCode, Body = response.Content.ReadAsStringAsync().Result, StatusCode = response.StatusCode };
64+
return new Response { IsSuccessful = response.IsSuccessStatusCode, Body = response.Content.ReadAsStringAsync().Result, Headers = response.Headers.ToDictionary(), StatusCode = response.StatusCode };
6565
}
6666

6767
/// <summary>

LessAnnoyingHttp/LessAnnoyingHttp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<Version>1.1.1</Version>
5+
<Version>1.2.0</Version>
66
<Authors>DemonExposer</Authors>
77
<Description>Simpler HTTP requests in .NET</Description>
88
<PackageTags>HTTP</PackageTags>

LessAnnoyingHttp/Response.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public class Response {
1818
/// The response of the HTTP request (is empty when the request failed)
1919
/// </summary>
2020
public string Body { get; internal init; } = "";
21+
22+
/// <summary>
23+
/// The headers sent back by the server
24+
/// </summary>
25+
public Dictionary<string, IEnumerable<string>> Headers { get; internal init; } = [];
2126

2227
/// <summary>
2328
/// Specifies whether the request was successful

0 commit comments

Comments
 (0)