Skip to content

PullZoneHandler.onOriginRequest should accept Promise<Request | Response> #63

@nextend

Description

@nextend

The current definition:

export declare type PullZoneHandler = {
    /**
     * Add a Middleware for the requests being processed.
     */
    onOriginRequest: (middleware: (ctx: OriginRequestContext) => Promise<Request> | Promise<Response>) => PullZoneHandler;
    /**
     * Add a Middleware for the response being processed.
     */
    onOriginResponse: (middleware: (ctx: OriginResponseContext) => Promise<Response>) => PullZoneHandler;
};

But I think it should also accept Promise<Request | Response> return type as the response might depend on the body of the callback function. Imagine a middleware, which return a Response on authentication failure, but returns the original Request on success.

Suggested:

export declare type PullZoneHandler = {
    /**
     * Add a Middleware for the requests being processed.
     */
    onOriginRequest: (middleware: (ctx: OriginRequestContext) => Promise<Request> | Promise<Response> | Promise<Request | Response>) => PullZoneHandler;
    /**
     * Add a Middleware for the response being processed.
     */
    onOriginResponse: (middleware: (ctx: OriginResponseContext) => Promise<Response>) => PullZoneHandler;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions