Logo

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
Azure functions isolated worker HTTP trigger: custom header disappears from response.

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;
}
Enter fullscreen mode Exit fullscreen mode

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);    
Enter fullscreen mode Exit fullscreen mode

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
Favicon
Secrets of a Successful Data Engineer
Favicon
Flex Consumption is not cheap (when in private VNET)
Favicon
🚀 Azure Function App: The Technical Backbone of Modern Applications
Favicon
Azure Function App (Flex Consumption) PowerShell Modules solution
Favicon
Azure functions isolated worker HTTP trigger: custom header disappears from response.
Favicon
The importance of release testing & questionable compiler optimizations
Favicon
Azure Functions with Python: Triggers
Favicon
Catching the Bus? How a Service Bus and Azure Functions Can Help Your Integration Reliability
Favicon
How to Create Timer Trigger Azure Functions with .NET 9: Step-by-Step Guide for Beginners
Favicon
Azure Function App (Flex Consumption) in private VNET via IaC
Favicon
Migrating Azure Function Calls to Minimal API with FastEndpoints
Favicon
Serverless Functions: Unlocking the Power of AWS Lambda, Azure Functions, and More
Favicon
Why Students Should Explore Microsoft Azure: The Cloud Platform for Your Future 🚀
Favicon
Cost Management in Azure: A Student-Friendly Guide to Managing Cloud Costs
Favicon
Azure Functions in .NET (C#) — The Ultimate Fun Version 🥳
Favicon
Building Scalable Applications with Azure Functions: Best Practices and Tips
Favicon
CREATING AN AZURE RESOURCE GROUP AND CLOUD STORAGE
Favicon
Returning Correct StatusCodes in Azure Function Apps
Favicon
Unlocking the Power of Azure Functions Flex Consumption Plan with Pulumi
Favicon
Implementing a Visitor Counter on Azure Resume Challenge
Favicon
Ready to Explore AI? Start with Azure AI Fundamentals!
Favicon
Handling Missing Configuration with Fallback Values in Azure Functions
Favicon
You don't need Dockerfile to containerise Azure Functions
Favicon
Azure Functions Hosting Models: In-Process vs. Isolated Process - What's Best for Your Project?
Favicon
How to Create Custom Middleware in Azure Functions: A Step-by-Step Guide with .NET 8
Favicon
Serverless Computing with .NET Core and Azure Functions
Favicon
Azure | Azure Functions By Example
Favicon
Improving Azure Functions Cold Boot
Favicon
Future-proof software development with the Azure Serverless Modulith
Favicon
Building business processes with Azure Durable Functions

Featured ones: