Azure / Azure/static-web-apps

Empty POST requests to an API have the content-type header removed

Open
#1,512 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
346
Forks
67
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

Empty POST requests to the API of an Azure Static Web App have the content-type header removed.

**To Reproduce**

[repro](https://github.com/geoffrich/swa-content-type-repro)

- create an Azure Function in your SWA that handles POST requests
- inspect the content-type header received by that function (either by logging or by returning the value)
- if the POST request has no body, the content-type header is not present. This is despite the content-type header being present on the original request from the browser

[live demo](https://delightful-pebble-0631aad1e.5.azurestaticapps.net/)

Click "submit" on the empty form. The response from the Azure function shows that no content-type header was passed to the function handler. However, if you inspect the request sent from the browser, the content-type header was sent -- so something is removing the header before it gets to the Azure function.

image

Submitting the second form (which has a form body) does not strip the content-type header.

**Expected behavior**

I expect the Azure function to receive the same content-type header that was sent from the browser.

**Device info (if applicable):**
n/a

**Additional context**

I maintain an Azure SWA adapter for SvelteKit and this behavior caused [this issue](https://github.com/geoffrich/svelte-adapter-azure-swa/issues/178).

This appears to be SWA specific, instead of a more general Azure function problem. I deployed the same Azure function code to a standalone function and it did not remove the content-type header.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked repro repository and live demo: send empty and non-empty POST requests to an Azure Function and compare the received Content-Type headers with the browser requests. Trace the Azure Static Web Apps API request path to find where the header is removed; done means an empty POST preserves the original Content-Type header when it reaches the function.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
api, backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.