Skip to content

Merge context  #1443

@ghermeto

Description

@ghermeto

What problem are you trying to solve?

Right now you can't use more than 1 plugin that makes use of context. For example, the following test case fails:

test('extending context', withServer, async (t, server) => {
	server.get('/', (req, res) => {
		res.json(req.headers);
	});

	const instance1 = got.extend({
		prefixUrl: server.url,
		responseType: 'json',
		context: { test: true }
	});

	const instance2 = instance1.extend({
		headers: { 'x-test': 'test' },
		context: { something: 'else' }
	});

	const instance3 = instance2.extend({
		hooks: {
			beforeRequest: [
				function injectClientInfo(options) {
					t.is(options.context.test, true)
				}
			]
		}
	});

	await instance3.get('');
});

Right now, context is not merged and not enumerable. This causes the plugin represented by instance2 to remove the context expected by instance1.

Describe the feature

Do a shallow merge on context with "defaults" in /core/index.ts and make it enumerable.

Implementation

I have availability to implement this feature if you decide this is a use-case you would like to support.

Checklist

  • I have read the documentation and made sure this feature doesn't already exist.

Metadata

Metadata

Assignees

Labels

enhancementThis change will extend Got features

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions