1- import { readFile } from 'node:fs/promises'
2- import { basename } from 'node:path'
3-
41const HTTP_METHODS = [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'PATCH' , 'OPTIONS' , 'TRACE' ]
52
6- const capitalizeHeaders = header => header . replace ( / ( ^ | - ) ( [ a - z ] ) / g, ( _ , dash , letter ) => dash + letter . toUpperCase ( ) ) ;
3+ const capitalizeHeaders = header => header . replace ( / ( ^ | - ) ( [ a - z ] ) / g, ( _ , dash , letter ) => dash + letter . toUpperCase ( ) )
74
85export async function plugin ( server , opts ) {
96 // We import this dynically to provide better error reporting in case
@@ -25,6 +22,7 @@ export async function plugin (server, opts) {
2522
2623 // We accept all content-types and parse them as buffer, so that PHP can
2724 // handle them
25+ server . removeAllContentTypeParsers ( )
2826 server . addContentTypeParser ( / ^ .* / , { parseAs : 'buffer' } , ( request , body , done ) => {
2927 done ( null , body )
3028 } )
@@ -100,16 +98,8 @@ export async function plugin (server, opts) {
10098}
10199
102100// A full URL string is needed for PHP, but Node.js splits that across a bunch of places.
103- function urlForRequest ( req ) {
101+ function urlForRequest ( req ) {
104102 const proto = req . raw . protocol ?? 'http:'
105103 const host = req . headers . host ?? 'localhost'
106104 return new URL ( req . url , `${ proto } //${ host } ` )
107105}
108-
109- // Currently header values must be arrays. Need to make it support single values too.
110- function fixHeaders ( headers ) {
111- return Object . fromEntries (
112- Object . entries ( headers )
113- . map ( ( [ key , value ] ) => [ key , [ value ] ] )
114- )
115- }
0 commit comments