mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
chore: Clean up code related to headers.
This commit is contained in:
committed by
Joachim Van Herwegen
parent
f08617b1c9
commit
30ee0f8dc6
@@ -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/' });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user