Skip to content

Commit d0de020

Browse files
HavenDVgithub-actions[bot]
andauthored
feat: Updated OpenAPI spec (#10)
Co-authored-by: github-actions[bot] <dependabot@bot.com>
1 parent 925ca13 commit d0de020

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

src/libs/StepFun/Generated/StepFun.OptionsSupport.g.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,84 @@ public interface IAutoSDKAuthorizationProvider
150150
global::StepFun.AutoSDKHookContext context);
151151
}
152152

153+
/// <summary>
154+
/// Marker keys stamped onto outgoing <see cref="global::System.Net.Http.HttpRequestMessage"/>
155+
/// instances so consumer <see cref="global::System.Net.Http.DelegatingHandler"/>s — and any
156+
/// other transport-layer code that runs after AutoSDK's send pipeline — can observe whether
157+
/// the resolved Authorization is call-scoped and opt out of overwriting it with a
158+
/// rotation-aware account-level credential.
159+
/// </summary>
160+
public static class AutoSDKHttpRequestOptions
161+
{
162+
/// <summary>
163+
/// Key under which <see cref="StampAuthorizationOverride"/> records the marker. Exposed
164+
/// for handlers that target frameworks older than .NET 5 and need to read the value
165+
/// through the legacy <c>HttpRequestMessage.Properties</c> bag.
166+
/// </summary>
167+
public const string AuthorizationOverrideKey = "AutoSDK.AuthorizationOverride";
168+
169+
#if NET5_0_OR_GREATER
170+
/// <summary>
171+
/// Strongly-typed <see cref="global::System.Net.Http.HttpRequestOptionsKey{TValue}"/> for
172+
/// the call-scoped Authorization marker on .NET 5+ targets. Consumers should prefer this
173+
/// over the legacy <c>HttpRequestMessage.Properties</c> bag where available.
174+
/// </summary>
175+
public static readonly global::System.Net.Http.HttpRequestOptionsKey<bool> AuthorizationOverride =
176+
new global::System.Net.Http.HttpRequestOptionsKey<bool>(AuthorizationOverrideKey);
177+
#endif
178+
179+
/// <summary>
180+
/// Stamps the call-scoped Authorization marker on <paramref name="request"/>. AutoSDK's
181+
/// built-in <see cref="AutoSDKAuthorizationProviderHook"/> calls this whenever the
182+
/// resolved auth came from a per-request override or a client-level
183+
/// <see cref="IAutoSDKAuthorizationProvider"/>. Hand-written SDK extensions that set a
184+
/// non-default <c>Authorization</c> header (e.g. a session-scoped bearer returned by an
185+
/// upstream poll) should call this too so downstream rotation handlers know to skip the
186+
/// overwrite.
187+
/// </summary>
188+
/// <param name="request"></param>
189+
public static void StampAuthorizationOverride(
190+
global::System.Net.Http.HttpRequestMessage? request)
191+
{
192+
if (request is null)
193+
{
194+
return;
195+
}
196+
197+
#if NET5_0_OR_GREATER
198+
request.Options.Set(AuthorizationOverride, true);
199+
#else
200+
#pragma warning disable CS0618 // HttpRequestMessage.Properties is obsolete in NET5+, but the only option below it.
201+
request.Properties[AuthorizationOverrideKey] = true;
202+
#pragma warning restore CS0618
203+
#endif
204+
}
205+
206+
/// <summary>
207+
/// Returns true when <see cref="StampAuthorizationOverride"/> previously marked the
208+
/// request as carrying a call-scoped Authorization.
209+
/// </summary>
210+
/// <param name="request"></param>
211+
public static bool HasAuthorizationOverride(
212+
global::System.Net.Http.HttpRequestMessage? request)
213+
{
214+
if (request is null)
215+
{
216+
return false;
217+
}
218+
219+
#if NET5_0_OR_GREATER
220+
return request.Options.TryGetValue(AuthorizationOverride, out var value) && value;
221+
#else
222+
#pragma warning disable CS0618
223+
return request.Properties.TryGetValue(AuthorizationOverrideKey, out var raw) &&
224+
raw is bool flag &&
225+
flag;
226+
#pragma warning restore CS0618
227+
#endif
228+
}
229+
}
230+
153231
/// <summary>
154232
/// Built-in <see cref="IAutoSDKHook"/> that consults
155233
/// <see cref="AutoSDKClientOptions.AuthorizationProvider"/> before every outgoing
@@ -176,6 +254,7 @@ public sealed class AutoSDKAuthorizationProviderHook : global::StepFun.AutoSDKHo
176254
ApplyAuthorization(context.Request, perRequest[index]);
177255
}
178256

257+
global::StepFun.AutoSDKHttpRequestOptions.StampAuthorizationOverride(context.Request);
179258
return;
180259
}
181260

@@ -195,6 +274,8 @@ public sealed class AutoSDKAuthorizationProviderHook : global::StepFun.AutoSDKHo
195274
{
196275
ApplyAuthorization(context.Request, resolved[index]);
197276
}
277+
278+
global::StepFun.AutoSDKHttpRequestOptions.StampAuthorizationOverride(context.Request);
198279
}
199280

200281
private static void ApplyAuthorization(

0 commit comments

Comments
 (0)