Skip to content

Commit 61484ec

Browse files
feat: Add optional URL parameter to FetchResponse (box/box-codegen#617) (#331)
1 parent e689140 commit 61484ec

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "ca891f7", "specHash": "544d370", "version": "1.4.0" }
1+
{ "engineHash": "f073ce3", "specHash": "544d370", "version": "1.4.0" }

Box.Sdk.Gen/Networking/Fetch.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ internal static async Task<FetchResponse> FetchAsync(FetchOptions options)
7474
{
7575
var response = result.Value!;
7676

77+
var url = response.RequestMessage?.RequestUri?.ToString() ?? request.RequestUri?.ToString() ?? options.Url;
7778
var statusCode = (int)response.StatusCode;
7879
var isRetryAfterPresent = response.Headers.Contains("retry-after");
7980
var isRetryAfterWithAcceptedPresent = isRetryAfterPresent && statusCode == 202;
@@ -82,8 +83,8 @@ internal static async Task<FetchResponse> FetchAsync(FetchOptions options)
8283
{
8384
seekableStream?.Dispose();
8485
return isStreamResponse ?
85-
new FetchResponse(status: statusCode, headers: response.Headers.ToDictionary(x => x.Key, x => x.Value.First())) { Content = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false) } :
86-
new FetchResponse(status: statusCode, headers: response.Headers.ToDictionary(x => x.Key, x => x.Value.First())) { Data = JsonUtils.JsonToSerializedData(await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false)) };
86+
new FetchResponse(status: statusCode, headers: response.Headers.ToDictionary(x => x.Key, x => x.Value.First())) { Url = url, Content = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false) } :
87+
new FetchResponse(status: statusCode, headers: response.Headers.ToDictionary(x => x.Key, x => x.Value.First())) { Url = url, Data = JsonUtils.JsonToSerializedData(await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false)) };
8788
}
8889

8990
if (attempt >= networkSession.RetryAttempts)

Box.Sdk.Gen/Networking/FetchResponse/FetchResponse.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
namespace Box.Sdk.Gen {
77
public class FetchResponse {
8+
/// <summary>
9+
/// URL of the response
10+
/// </summary>
11+
public string? Url { get; init; }
12+
813
/// <summary>
914
/// HTTP status code of the response
1015
/// </summary>

0 commit comments

Comments
 (0)