mirror of
https://github.com/morluto/rea
synced 2026-10-26 06:16:17 -04:00
0b1af48a37
Parse MIME parameters once with strict quoted-value and duplicate handling, and compare equivalent default binary profiles. Keep excluded HAR MIME unknown, explicit framing independent, and nominal gRPC sanitization intact across malformed or repeated declarations. Add public CLI/MCP and native-header regressions with source identity and partial-coverage assertions. Preserve upstream wire and schema admission. Fixes #6836
88 lines
2.4 KiB
TypeScript
88 lines
2.4 KiB
TypeScript
import { create, toBinary } from "@bufbuild/protobuf";
|
|
import { FileDescriptorSetSchema } from "@bufbuild/protobuf/wkt";
|
|
|
|
export const protobufFrame = (body: Buffer, flag = 0): Buffer => {
|
|
const header = Buffer.alloc(5);
|
|
header[0] = flag;
|
|
header.writeUInt32BE(body.length, 1);
|
|
return Buffer.concat([header, body]);
|
|
};
|
|
|
|
export const protobufCaptureBody = () =>
|
|
Buffer.concat([
|
|
protobufFrame(Buffer.from("0a0568656c6c6f12020102", "hex")),
|
|
protobufFrame(Buffer.from("grpc-status: 0\r\n"), 128),
|
|
]);
|
|
|
|
/** Original fixture schema; independent expected field values come from the literal wire bytes. */
|
|
export const protobufCaptureDescriptor = () =>
|
|
toBinary(
|
|
FileDescriptorSetSchema,
|
|
create(FileDescriptorSetSchema, {
|
|
file: [
|
|
{
|
|
name: "capture.proto",
|
|
package: "capture",
|
|
syntax: "proto3",
|
|
messageType: [
|
|
{
|
|
name: "Message",
|
|
field: [
|
|
{ name: "sentence", number: 1, type: 9, label: 1 },
|
|
{ name: "values", number: 2, type: 13, label: 3 },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
}),
|
|
);
|
|
|
|
export const protobufHar = (
|
|
body: Buffer = protobufCaptureBody(),
|
|
mimeType = "application/grpc-web+proto",
|
|
additionalBodies: readonly Buffer[] = [],
|
|
responseHeaders: readonly {
|
|
readonly name: string;
|
|
readonly value: string;
|
|
}[] = [],
|
|
) =>
|
|
JSON.stringify({
|
|
log: {
|
|
version: "1.2",
|
|
creator: { name: "REA original fixture", version: "1" },
|
|
entries: [body, ...additionalBodies].map((body) => ({
|
|
startedDateTime: "2026-10-20T00:00:00Z",
|
|
time: 1,
|
|
request: {
|
|
method: "POST",
|
|
url: "https://example.invalid/api",
|
|
httpVersion: "HTTP/1.1",
|
|
cookies: [],
|
|
headers: [],
|
|
queryString: [],
|
|
headersSize: -1,
|
|
bodySize: 0,
|
|
},
|
|
response: {
|
|
status: 200,
|
|
statusText: "OK",
|
|
httpVersion: "HTTP/1.1",
|
|
cookies: [],
|
|
headers: responseHeaders,
|
|
redirectURL: "",
|
|
headersSize: -1,
|
|
bodySize: body.length,
|
|
content: {
|
|
size: body.length,
|
|
mimeType,
|
|
text: body.toString("base64"),
|
|
encoding: "base64",
|
|
},
|
|
},
|
|
cache: {},
|
|
timings: { send: 0, wait: 1, receive: 0 },
|
|
})),
|
|
},
|
|
});
|