Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Remove bespoken data when accesing the proxied server (Relates #393)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Perata committed Jan 3, 2018
1 parent 39ee510 commit ee50cf6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/client/bespoke-client.ts
Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions lib/core/webhook-request.ts
Expand Up @@ -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 {
Expand Down

0 comments on commit ee50cf6

Please sign in to comment.