dev-resources.site
for different kinds of informations.
Azure functions isolated worker HTTP trigger: custom header disappears from response.
Published at
12/12/2024
Categories
azurefunctions
Author
helapau
Categories
1 categories in total
azurefunctions
open
Author
7 person written this
helapau
open
So I had a simple Azure function like this:
public async Task<HttpResponseData> GetCountries(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "countries")] HttpRequestData req, FunctionContext ctx)
{
var result = await _countriesService.GetCountries();
var response = req.CreateResponse(HttpStatusCode.OK);
await response.WriteAsJsonAsync(result);
// ctx.GetCorrelationId() is an extension method on the FunctionContext
response.Headers.Add("x-correlationId", ctx.GetCorrelationId());
return response;
}
When I stopped on the line return response
with debugger, I saw that the response did indeed contain the custom header 'x-correlationId'. However, the client (I tried Postman and browser) did not receive this header.
The solution was to first insert the custom header, and then write the body into it. So the sequence is:
response.Headers.Add("x-correlationId", ctx.GetCorrelationId());
await response.WriteAsJsonAsync(result);
Unfortunately, I don't know what was really happening here. Why the debugger showed me that the header was there even though the response was somehow modified by the WriteAsJsonAsync
method.
azurefunctions Article's
30 articles in total
Secrets of a Successful Data Engineer
read article
Flex Consumption is not cheap (when in private VNET)
read article
🚀 Azure Function App: The Technical Backbone of Modern Applications
read article
Azure Function App (Flex Consumption) PowerShell Modules solution
read article
Azure functions isolated worker HTTP trigger: custom header disappears from response.
currently reading
The importance of release testing & questionable compiler optimizations
read article
Azure Functions with Python: Triggers
read article
Catching the Bus? How a Service Bus and Azure Functions Can Help Your Integration Reliability
read article
How to Create Timer Trigger Azure Functions with .NET 9: Step-by-Step Guide for Beginners
read article
Azure Function App (Flex Consumption) in private VNET via IaC
read article
Migrating Azure Function Calls to Minimal API with FastEndpoints
read article
Serverless Functions: Unlocking the Power of AWS Lambda, Azure Functions, and More
read article
Why Students Should Explore Microsoft Azure: The Cloud Platform for Your Future 🚀
read article
Cost Management in Azure: A Student-Friendly Guide to Managing Cloud Costs
read article
Azure Functions in .NET (C#) — The Ultimate Fun Version 🥳
read article
Building Scalable Applications with Azure Functions: Best Practices and Tips
read article
CREATING AN AZURE RESOURCE GROUP AND CLOUD STORAGE
read article
Returning Correct StatusCodes in Azure Function Apps
read article
Unlocking the Power of Azure Functions Flex Consumption Plan with Pulumi
read article
Implementing a Visitor Counter on Azure Resume Challenge
read article
Ready to Explore AI? Start with Azure AI Fundamentals!
read article
Handling Missing Configuration with Fallback Values in Azure Functions
read article
You don't need Dockerfile to containerise Azure Functions
read article
Azure Functions Hosting Models: In-Process vs. Isolated Process - What's Best for Your Project?
read article
How to Create Custom Middleware in Azure Functions: A Step-by-Step Guide with .NET 8
read article
Serverless Computing with .NET Core and Azure Functions
read article
Azure | Azure Functions By Example
read article
Improving Azure Functions Cold Boot
read article
Future-proof software development with the Azure Serverless Modulith
read article
Building business processes with Azure Durable Functions
read article
Featured ones: