Skip to content

undici.Request.clone does not copy dispatcher #3630

@berndfuhrmann

Description

@berndfuhrmann

Bug Description

Reproducible By

Consider this code:

async function test() {
    const undici = require('undici');

    class CustomAgent extends undici.Agent {
        constructor() {
            super({
                keepAliveTimeout: 10,
                keepAliveMaxTimeout: 10
            });
        }
        dispatch(options, handler) {
            console.log("DISPATCH");
            return super.dispatch(options, handler);
        }
    }

    const request = new undici.Request("https://example.org", {
        dispatcher: new CustomAgent()
    });

    // will make an HTTP call and print "DISPATCH"
    await undici.fetch(request);

    // will make an HTTP call, but not print "DISPATCH"
    await undici.fetch(request.clone());
}

test();

Expected Behavior

In the code above, I would expect both fetch calls to use the dispatcher.

Logs & Screenshots

none.

Environment

NodeJS, Version v22.9.0

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions