-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TEX-537] Optional support for unframing
grpc-web+json
requests. (#501
) Add a new option for unframing `application/grpc-web+json` requests to be just `application/json` requests if the request is to a whitelisted hostname. This unframing is performed by mutating the received request before doing anything else with it, including passing it upstream or searching for existing tapes. This has the effect that, for all intents and purposes, the request is an `application/json` request for the purposes of persistence, similarity scoring, and proxying.
- Loading branch information
1 parent
f57d0d7
commit e1bc576
Showing
5 changed files
with
183 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import axios from "axios"; | ||
import { PROXAY_HOST } from "./config"; | ||
import { PROXAY_HOST, TEST_SERVER_PORT } from "./config"; | ||
import { setupServers } from "./setup"; | ||
import { | ||
BINARY_PATH, | ||
BINARY_RESPONSE, | ||
GRPC_WEB_JSON_PATH, | ||
SIMPLE_TEXT_PATH, | ||
SIMPLE_TEXT_RESPONSE, | ||
UTF8_PATH, | ||
|
@@ -36,3 +37,85 @@ describe("Passthrough", () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe("Passthrough with grpc-web+json unframing", () => { | ||
setupServers({ mode: "passthrough", enableUnframeGrpcWebJson: true }); | ||
|
||
test("response: simple text", async () => { | ||
const response = await axios.get(`${PROXAY_HOST}${SIMPLE_TEXT_PATH}`); | ||
expect(response.data).toBe(SIMPLE_TEXT_RESPONSE); | ||
}); | ||
|
||
test("response: utf-8", async () => { | ||
const response = await axios.get(`${PROXAY_HOST}${UTF8_PATH}`); | ||
expect(response.data).toBe(UTF8_RESPONSE); | ||
}); | ||
|
||
test("response: binary", async () => { | ||
const response = await axios.get(`${PROXAY_HOST}${BINARY_PATH}`, { | ||
responseType: "arraybuffer", | ||
}); | ||
expect(response.data).toEqual(BINARY_RESPONSE); | ||
}); | ||
|
||
test("can pick any tape", async () => { | ||
await axios.post(`${PROXAY_HOST}/__proxay/tape`, { | ||
tape: "new-tape", | ||
}); | ||
}); | ||
|
||
test("unframes a grpc-web+json request", async () => { | ||
const requestBody = Buffer.from([ | ||
0, | ||
0, | ||
0, | ||
0, | ||
31, | ||
123, | ||
34, | ||
101, | ||
109, | ||
97, | ||
105, | ||
108, | ||
34, | ||
58, | ||
34, | ||
102, | ||
111, | ||
111, | ||
46, | ||
98, | ||
97, | ||
114, | ||
64, | ||
101, | ||
120, | ||
97, | ||
109, | ||
112, | ||
108, | ||
101, | ||
46, | ||
99, | ||
111, | ||
109, | ||
34, | ||
125, | ||
]); | ||
const response = await axios.post( | ||
`${PROXAY_HOST}${GRPC_WEB_JSON_PATH}`, | ||
requestBody, | ||
{ | ||
headers: { | ||
"content-type": "application/grpc-web+json", | ||
host: `localhost:${TEST_SERVER_PORT}`, | ||
}, | ||
} | ||
); | ||
expect(response.headers["content-type"]).toBe( | ||
"application/json; charset=utf-8" | ||
); | ||
expect(response.data).toEqual({ email: "[email protected]" }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters