@@ -12,7 +12,7 @@ import { Readable } from "stream"
12
12
import * as tls from "tls"
13
13
import * as url from "url"
14
14
import { HttpCode , HttpError } from "../common/http"
15
- import { normalize , Options , plural , split } from "../common/util"
15
+ import { arrayify , normalize , Options , plural , split , trimSlashes } from "../common/util"
16
16
import { SocketProxyProvider } from "./socket"
17
17
import { getMediaMime , paths } from "./util"
18
18
@@ -287,7 +287,7 @@ export abstract class HttpProvider {
287
287
* Helper to error on invalid methods (default GET).
288
288
*/
289
289
protected ensureMethod ( request : http . IncomingMessage , method ?: string | string [ ] ) : void {
290
- const check = Array . isArray ( method ) ? method : [ method || "GET" ]
290
+ const check = arrayify ( method || "GET" )
291
291
if ( ! request . method || ! check . includes ( request . method ) ) {
292
292
throw new HttpError ( `Unsupported method ${ request . method } ` , HttpCode . BadRequest )
293
293
}
@@ -559,7 +559,7 @@ export class HttpServer {
559
559
} ,
560
560
...args ,
561
561
)
562
- const endpoints = ( typeof endpoint === "string" ? [ endpoint ] : endpoint ) . map ( ( e ) => e . replace ( / ^ \/ + | \/ + $ / g , "" ) )
562
+ const endpoints = arrayify ( endpoint ) . map ( trimSlashes )
563
563
endpoints . forEach ( ( endpoint ) => {
564
564
if ( / \/ / . test ( endpoint ) ) {
565
565
throw new Error ( `Only top-level endpoints are supported (got ${ endpoint } )` )
0 commit comments