Read the first value of a request header¶
HttpRequestExtensions.TryGetFirstHeader reads the first value of a request header without ever throwing.
| Field | Value |
|---|---|
| Operation ID | OP-10 |
| Trigger | Compose the trace and log message, step 2, and any consumer call. |
| Inputs | HttpRequestMessage, header key |
| Outputs | string |
| Primary components | HttpRequestExtensions.TryGetFirstHeader(this HttpRequestMessage, string) |
| Entry point | src/SAIF.Web.API/HttpRequestExtensions.cs |
Steps¶
- If
request.Headers != nullandrequest.Headers.TryGetValues(key, out values)succeeds, returnvalues.FirstOrDefault()(BR-WEBAPI-019). - May return
nullif the header exists with an empty value collection.* - Otherwise return
""(BR-WEBAPI-019). - Never throws on a missing header.
Process flow¶
flowchart TD
Start(["Called from OP-05 step<br>2, or any consumer"]) --> HasHeaders{"Headers != null and<br>TryGetValues succeeds?"}
HasHeaders -->|Yes| First["return<br>values.FirstOrDefault()"]
HasHeaders -->|No| Empty["return \"\""]
Failure and edge-case behavior¶
- Never throws; a header present with an empty value collection can yield
nullrather than"".*
Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Related documentation¶
Sources¶
src/SAIF.Web.API/HttpRequestExtensions.cs