99 yellow ,
1010} from "kleur/colors" ;
1111import { HttpError , LogLevel , SharedHeaders } from "miniflare:shared" ;
12- import { LOCAL_EXPLORER_BASE_PATH } from "../../plugins/core/constants" ;
1312import { isCompressedByCloudflareFL } from "../../shared/mime-types" ;
14- import { CoreBindings , CoreHeaders } from "./constants" ;
13+ import { CoreBindings , CoreHeaders , CorePaths } from "./constants" ;
1514import { handleEmail } from "./email" ;
1615import { STATUS_CODES } from "./http" ;
1716import { matchRoutes , WorkerRoute } from "./routing" ;
@@ -469,9 +468,14 @@ export default <ExportedHandler<Env>>{
469468 } ;
470469 request = new Request ( request , { cf } ) ;
471470
472- // The magic proxy client (used by getPlatformProxy) will always specify an operation
473- const isProxy = request . headers . get ( CoreHeaders . OP ) !== null ;
474- if ( isProxy ) return handleProxy ( request , env ) ;
471+ // The magic proxy client (used by getPlatformProxy)
472+ if ( new URL ( request . url ) . pathname === CorePaths . PLATFORM_PROXY ) {
473+ if ( request . headers . get ( CoreHeaders . OP ) !== null ) {
474+ return handleProxy ( request , env ) ;
475+ }
476+
477+ return new Response ( "Invalid proxy request" , { status : 400 } ) ;
478+ }
475479
476480 // `dispatchFetch()` will always inject this header. When
477481 // calling this function, we never want to display the pretty-error page.
@@ -487,8 +491,8 @@ export default <ExportedHandler<Env>>{
487491 if ( env [ CoreBindings . SERVICE_LOCAL_EXPLORER ] ) {
488492 const preRewriteUrl = new URL ( request . url ) ;
489493 if (
490- preRewriteUrl . pathname === LOCAL_EXPLORER_BASE_PATH ||
491- preRewriteUrl . pathname . startsWith ( `${ LOCAL_EXPLORER_BASE_PATH } /` )
494+ preRewriteUrl . pathname === CorePaths . EXPLORER ||
495+ preRewriteUrl . pathname . startsWith ( `${ CorePaths . EXPLORER } /` )
492496 ) {
493497 validateLocalExplorerRequest (
494498 request ,
@@ -514,18 +518,18 @@ export default <ExportedHandler<Env>>{
514518 try {
515519 if ( env [ CoreBindings . SERVICE_LOCAL_EXPLORER ] ) {
516520 if (
517- url . pathname === LOCAL_EXPLORER_BASE_PATH ||
518- url . pathname . startsWith ( `${ LOCAL_EXPLORER_BASE_PATH } /` )
521+ url . pathname === CorePaths . EXPLORER ||
522+ url . pathname . startsWith ( `${ CorePaths . EXPLORER } /` )
519523 ) {
520524 return await env [ CoreBindings . SERVICE_LOCAL_EXPLORER ] . fetch ( request ) ;
521525 }
522526 }
523527 if ( env [ CoreBindings . TRIGGER_HANDLERS ] ) {
524528 if (
525- url . pathname === "/cdn-cgi/handler/scheduled" ||
526- /* legacy URL path */ url . pathname === "/cdn-cgi/mf/scheduled"
529+ url . pathname === CorePaths . SCHEDULED ||
530+ /* legacy URL path */ url . pathname === CorePaths . LEGACY_SCHEDULED
527531 ) {
528- if ( url . pathname === "/cdn-cgi/mf/scheduled" ) {
532+ if ( url . pathname === CorePaths . LEGACY_SCHEDULED ) {
529533 ctx . waitUntil (
530534 env [ CoreBindings . SERVICE_LOOPBACK ] . fetch (
531535 "http://localhost/core/log" ,
@@ -534,15 +538,15 @@ export default <ExportedHandler<Env>>{
534538 headers : {
535539 [ SharedHeaders . LOG_LEVEL ] : LogLevel . WARN . toString ( ) ,
536540 } ,
537- body : `Triggering scheduled handlers via a request to \`/cdn-cgi/mf/scheduled \` is deprecated, and will be removed in a future version of Miniflare. Instead, send a request to \`/cdn-cgi/handler/scheduled \`` ,
541+ body : `Triggering scheduled handlers via a request to \`${ CorePaths . LEGACY_SCHEDULED } \` is deprecated, and will be removed in a future version of Miniflare. Instead, send a request to \`${ CorePaths . SCHEDULED } \`` ,
538542 }
539543 )
540544 ) ;
541545 }
542546 return await handleScheduled ( url . searchParams , service ) ;
543547 }
544548
545- if ( url . pathname === "/cdn-cgi/handler/email" ) {
549+ if ( url . pathname === CorePaths . EMAIL ) {
546550 return await handleEmail (
547551 url . searchParams ,
548552 request ,
@@ -552,9 +556,9 @@ export default <ExportedHandler<Env>>{
552556 ) ;
553557 }
554558
555- if ( url . pathname . startsWith ( "/cdn-cgi/handler/" ) ) {
559+ if ( url . pathname . startsWith ( CorePaths . HANDLER_PREFIX ) ) {
556560 return new Response (
557- `"${ url . pathname } " is not a valid handler. Did you mean to use "/cdn-cgi/handler/scheduled " or "/cdn-cgi/handler/email "?` ,
561+ `"${ url . pathname } " is not a valid handler. Did you mean to use "${ CorePaths . SCHEDULED } " or "${ CorePaths . EMAIL } "?` ,
558562 { status : 404 }
559563 ) ;
560564 }
0 commit comments