diff --git a/lib/client/bespoke-client.ts b/lib/client/bespoke-client.ts index 1318ef6f..2ddab83b 100644 --- a/lib/client/bespoke-client.ts +++ b/lib/client/bespoke-client.ts @@ -121,7 +121,7 @@ export class BespokeClient { const tcpClient = new TCPClient(request.id() + ""); const httpBuffer = new HTTPBuffer(); - tcpClient.transmit(self.targetDomain, self.targetPort, request.rawContents, function(data: Buffer, error: NetworkErrorType, message: string) { + tcpClient.transmit(self.targetDomain, self.targetPort, request.requestWithoutBespokenData(), function(data: Buffer, error: NetworkErrorType, message: string) { if (data != null) { // Grab the body of the response payload diff --git a/lib/core/webhook-request.ts b/lib/core/webhook-request.ts index 68558c05..897354ea 100644 --- a/lib/core/webhook-request.ts +++ b/lib/core/webhook-request.ts @@ -106,13 +106,19 @@ export class WebhookRequest { return nodeValue; } - private extractNodeIdFromRequest(tcpString: string) { - return tcpString.replace("/?node-id=" + this.nodeID(), "/"); + private removeBespokenQueries(httpLine: string): string { + return httpLine.replace("&node-id=" + this.nodeID(), "") + .replace("node-id=" + this.nodeID(), "") + .replace("&bespoken-key=" + this.nodeID(), "") + .replace("bespoken-key=" + this.nodeID(), "") + .replace("? HTTP", " HTTP"); // in case the only parameters were bespoken ones } - // Turns the webhook HTTP request into straight TCP payload - public toTCP (): string { - return this.extractNodeIdFromRequest(this.rawContents.toString()); + public requestWithoutBespokenData(): Buffer { + const firstLineBreak = this.rawContents.indexOf("\n"); + const httpLine = this.rawContents.slice(0, firstLineBreak).toString(); + return Buffer.concat([Buffer.from(this.removeBespokenQueries(httpLine)), + this.rawContents.slice(firstLineBreak)]); } public isJSON(): boolean {