Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing content-type header for empty POST requests #179

Merged
merged 2 commits into from
Jul 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions files/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export async function index(context) {
const request = toRequest(context);

if (debug) {
context.log(
'Starting request',
context?.req?.method,
context?.req?.headers?.['x-ms-original-url']
);
context.log(`Original request: ${JSON.stringify(context)}`);
context.log(`Request: ${JSON.stringify(request)}`);
}

Expand Down Expand Up @@ -66,6 +72,12 @@ function toRequest(context) {
// this header contains the URL the user requested
const originalUrl = headers['x-ms-original-url'];

// SWA strips content-type headers from empty POST requests, but SK form actions require the header
// https://github.com/geoffrich/svelte-adapter-azure-swa/issues/178
if (method === 'POST' && !body && !headers['content-type']) {
headers['content-type'] = 'application/x-www-form-urlencoded';
}

/** @type {RequestInit} */
const init = {
method,
Expand Down
Loading