Skip to content

Unexpected behavior with beforeRetry and baseUrl #867

@wesleytodd

Description

@wesleytodd

Describe the bug

Actual behavior

The examples show updating hostname in the options, but if you originally used baseUrl and then try to modify baseUrl in your hook, it does not re-derive the url. It seems like inconsistent/unexpected behavior.

Expected behavior

Run the same logic which sets hostname, path, etc if the hook modifies baseUrl

Code to reproduce

const r = got.extend('https://foo.com/path', {
	hooks: {
		beforeRetry: [
			(options, response) => {
				options.baseUrl = 'https://bar.com/other-path';
			}
		]
	}
});

await r('/more/path')

In the above example I would expect two requests (if the first failed):

https://foo.com/path/path/more/path
https://bar.com/other-path/more/path

What happens is a second request to https://foo.com/path/path/more/path.

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingAPI changes / behavior changes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions