28 lines
1.3 KiB
JavaScript
28 lines
1.3 KiB
JavaScript
import { ACTION_HEADER } from '../../client/components/app-router-headers';
|
|
export function getServerActionRequestMetadata(req) {
|
|
let actionId;
|
|
let contentType;
|
|
if (req.headers instanceof Headers) {
|
|
actionId = req.headers.get(ACTION_HEADER.toLowerCase()) ?? null;
|
|
contentType = req.headers.get('content-type');
|
|
} else {
|
|
actionId = req.headers[ACTION_HEADER.toLowerCase()] ?? null;
|
|
contentType = req.headers['content-type'] ?? null;
|
|
}
|
|
const isURLEncodedAction = Boolean(req.method === 'POST' && contentType === 'application/x-www-form-urlencoded');
|
|
const isMultipartAction = Boolean(req.method === 'POST' && (contentType == null ? void 0 : contentType.startsWith('multipart/form-data')));
|
|
const isFetchAction = Boolean(actionId !== undefined && typeof actionId === 'string' && req.method === 'POST');
|
|
const isPossibleServerAction = Boolean(isFetchAction || isURLEncodedAction || isMultipartAction);
|
|
return {
|
|
actionId,
|
|
isURLEncodedAction,
|
|
isMultipartAction,
|
|
isFetchAction,
|
|
isPossibleServerAction
|
|
};
|
|
}
|
|
export function getIsPossibleServerAction(req) {
|
|
return getServerActionRequestMetadata(req).isPossibleServerAction;
|
|
}
|
|
|
|
//# sourceMappingURL=server-action-request-meta.js.map
|