Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly set the content-type on HTTPReceiver responses to the /slack/install route #1280

Merged
merged 3 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/receivers/HTTPReceiver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,14 @@ describe('HTTPReceiver', function () {
const fakeRes: ServerResponse = sinon.createStubInstance(ServerResponse) as unknown as ServerResponse;
const writeHead = sinon.fake();
const end = sinon.fake();
const setHeader = sinon.fake();
fakeRes.writeHead = writeHead;
fakeRes.end = end;
fakeRes.setHeader = setHeader;
await receiver.requestListener(fakeReq, fakeRes);
assert(installProviderStub.generateInstallUrl.calledWith(sinon.match({ metadata, scopes, userScopes })));
assert.isTrue(writeHead.calledWith(200));
assert.isTrue(setHeader.calledWith('Content-Type', 'text/html; charset=utf-8'));
});

it('should use a custom HTML renderer for the install path webpage', async function () {
Expand Down
2 changes: 1 addition & 1 deletion src/receivers/HTTPReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,8 @@ export default class HTTPReceiver implements Receiver {

// Serve a basic HTML page including the "Add to Slack" button.
// Regarding headers:
// - Content-Type is usually automatically detected by browsers
// - Content-Length is not used because Transfer-Encoding='chunked' is automatically used.
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.writeHead(200);
res.end(body);
}
Expand Down