Skip to content

Commit

Permalink
force more plaintext headers
Browse files Browse the repository at this point in the history
  • Loading branch information
d-fischer committed Jan 31, 2022
1 parent 333dc23 commit 8afa5b4
Show file tree
Hide file tree
Showing 4 changed files with 7,570 additions and 7,923 deletions.
2 changes: 1 addition & 1 deletion packages/eventsub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@twurple/auth": "^5.0.16",
"@twurple/common": "^5.0.16",
"@types/express-serve-static-core": "^4.17.24",
"httpanda": "^0.4.4",
"httpanda": "^0.4.6",
"tslib": "^2.0.3"
},
"devDependencies": {
Expand Down
19 changes: 14 additions & 5 deletions packages/eventsub/src/EventSubBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1028,31 +1028,38 @@ export abstract class EventSubBase extends EventEmitter {
setTimeout(() => this._seenEventIds.delete(messageId), 10 * 60 * 1000);
subscription._handleData((data as EventSubNotificationBody).event);
}
res.setHeader('Content-Type', 'text/plain');
res.writeHead(202);
res.end();
res.end('OK');
} else if (type === 'revocation') {
this._dropSubscription(subscription.id);
this._dropTwitchSubscription(subscription.id);
this.emit(this.onRevoke, subscription);
this._logger.debug(`Subscription revoked by Twitch for event: ${id}`);
res.setHeader('Content-Type', 'text/plain');
res.writeHead(202);
res.end('OK');
} else {
this._logger.warn(`Unknown action ${type} for event: ${id}`);
res.setHeader('Content-Type', 'text/plain');
res.writeHead(400);
res.end();
res.end('Not OK');
}
} else {
this._logger.warn(`Could not verify action ${type} of event: ${id}`);
if (type === 'webhook_callback_verification') {
this.emit(this.onVerify, false, subscription);
}
res.setHeader('Content-Type', 'text/plain');
res.writeHead(410);
res.end();
res.end('Not OK');
}
}
} else {
this._logger.warn(`Action ${type} of unknown event attempted: ${id}`);
res.setHeader('Content-Type', 'text/plain');
res.writeHead(410);
res.end();
res.end('Not OK');
}
next();
};
Expand All @@ -1064,8 +1071,9 @@ export abstract class EventSubBase extends EventEmitter {
if (twitchSub) {
await this._apiClient.eventSub.deleteSubscription(twitchSub.id);
this._logger.debug(`Dropped legacy subscription for event: ${req.params.id}`);
res.setHeader('Content-Type', 'text/plain');
res.writeHead(410);
res.end();
res.end('Not OK');
} else {
next();
}
Expand All @@ -1075,6 +1083,7 @@ export abstract class EventSubBase extends EventEmitter {
protected _createHandleHealthRequest(): RequestHandler {
return async (req, res) => {
res.setHeader('Content-Type', 'text/plain');
res.writeHead(200);
res.end('@twurple/eventsub is listening here');
};
}
Expand Down
7 changes: 4 additions & 3 deletions packages/eventsub/src/EventSubListener.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Enumerable } from '@d-fischer/shared-utils';
import { rtfm } from '@twurple/common';
import type { Request } from 'httpanda';
import { Server } from 'httpanda';
import type { NextFunction, Request, Response } from 'httpanda';
import { defaultOnError, Server } from 'httpanda';
import type { ConnectionAdapter } from './adapters/ConnectionAdapter';
import type { EventSubBaseConfig } from './EventSubBase';
import { EventSubBase } from './EventSubBase';
Expand Down Expand Up @@ -66,11 +66,12 @@ export class EventSubListener extends EventSubBase {
const server = this._adapter.createHttpServer();
this._server = new Server({
server,
onError: (e, req: Request) => {
onError: (e, req: Request, res: Response, next: NextFunction) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (e.code === 404) {
this._logger.warn(`Access to unknown URL/method attempted: ${req.method!} ${req.url!}`);
}
defaultOnError(e, req, res, next);
}
});
// needs to be first in chain but run last, for proper logging of status
Expand Down

0 comments on commit 8afa5b4

Please sign in to comment.