| 92 | * @param {import('@sveltejs/kit').RequestEvent} event |
| 93 | */ |
| 94 | export function is_endpoint_request(event) { |
| 95 | const { method, headers } = event.request; |
| 96 | |
| 97 | // These methods exist exclusively for endpoints |
| 98 | if (ENDPOINT_METHODS.includes(method) && !PAGE_METHODS.includes(method)) { |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | // use:enhance uses a custom header to disambiguate |
| 103 | if (method === 'POST' && headers.get('x-sveltekit-action') === 'true') return false; |
| 104 | |
| 105 | // GET/POST requests may be for endpoints or pages. We prefer endpoints if this isn't a text/html request |
| 106 | const accept = event.request.headers.get('accept') ?? '*/*'; |
| 107 | return negotiate(accept, ['*', 'text/html']) !== 'text/html'; |
| 108 | } |