chore: Clean up code related to headers.

This commit is contained in:
Ruben Verborgh
2020-11-22 21:58:19 +01:00
committed by Joachim Van Herwegen
parent f08617b1c9
commit 30ee0f8dc6
5 changed files with 34 additions and 39 deletions

View File

@@ -15,18 +15,28 @@ describe('A BasicTargetExtractor', (): void => {
await expect(extractor.handle({ url: 'url', headers: {}} as any)).rejects.toThrow('Missing Host header');
});
it('errors if the host is invalid.', async(): Promise<void> => {
await expect(extractor.handle({ url: 'url', headers: { host: 'test.com/forbidden' }} as any))
.rejects.toThrow('The request has an invalid Host header: test.com/forbidden');
});
it('returns the input URL.', async(): Promise<void> => {
await expect(extractor.handle({ url: 'url', headers: { host: 'test.com' }} as any))
.resolves.toEqual({ path: 'http://test.com/url' });
});
it('supports host:port combinations.', async(): Promise<void> => {
await expect(extractor.handle({ url: 'url', headers: { host: 'localhost:3000' }} as any))
.resolves.toEqual({ path: 'http://localhost:3000/url' });
});
it('uses https protocol if the connection is secure.', async(): Promise<void> => {
await expect(extractor.handle(
{ url: 'url', headers: { host: 'test.com' }, connection: { encrypted: true } as any } as any,
)).resolves.toEqual({ path: 'https://test.com/url' });
});
it('encodes relevant characters.', async(): Promise<void> => {
it('encodes paths.', async(): Promise<void> => {
await expect(extractor.handle({ url: '/a%20path%26/name', headers: { host: 'test.com' }} as any))
.resolves.toEqual({ path: 'http://test.com/a%20path%26/name' });
@@ -36,4 +46,9 @@ describe('A BasicTargetExtractor', (): void => {
await expect(extractor.handle({ url: '/path&%26/name', headers: { host: 'test.com' }} as any))
.resolves.toEqual({ path: 'http://test.com/path%26%26/name' });
});
it('encodes hosts.', async(): Promise<void> => {
await expect(extractor.handle({ url: '/', headers: { host: '點看' }} as any))
.resolves.toEqual({ path: 'http://xn--c1yn36f/' });
});
});