Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ fileignoreconfig:
- "a project name passed on argv to the project resolver"
- "expect\\(Object.keys\\(DEPENDENCIES\\)\\).toEqual\\(\\['project', 'env'\\]\\)"
- filename: AGENTS.md
checksum: 86abf6589263684bab1a2e418764916059b59e95ac5e465c3820ecf8ac82be86
checksum: 17042b1f06e9955cf1159c8ac96f6ed300083c77a8d5fe48db64d3880d3e7fa2
allowed_patterns:
- "Do not add an exemption to a guard to make a new file pass"
- "passes its own error wording to `client.request\\(req, MESSAGES\\)`"
Expand Down Expand Up @@ -286,7 +286,7 @@ fileignoreconfig:
- filename: test/integration/projects-list-command.test.ts
checksum: 6709766943430b80aad2d7200102d936a92321e86c41f66d6a60a5baf82a81bf
- filename: src/functions/cloud-functions.test.ts
checksum: 626305f8439f9b04652c287465e08ef681e9ae1eb3547313d5a8bbb5ff70a342
checksum: a099f552d4c8ac79678ff2b2fa83e82e29d083ea0d267e601e269cbd5507acc6
- filename: src/functions/function.errors.ts
checksum: cad477cf24c97bf3395427235ca1de0f305369d05d61c21a83435654df2269e3
- filename: src/transport/proxy.test.ts
Expand Down
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,9 @@ The approved differences from V1 are these, and only these:
Buffer, all up to Lambda's 6mb cap. `request.cookies` is the parsed `Cookie` header, or `{}`.
`request.query` also holds the path parameters, which win over a query value of the same name
(`/items/abc?id=zzz` → `{ id: 'abc' }`), as on AWS (CL-8970); Azure and GCP (V1) keep them only
in `request.params`.
in `request.params`. The query string and an urlencoded body are parsed flat with Node's
`querystring`, as on AWS (CL-8970): `a[b]=1` stays the key `'a[b]'` and a repeated key becomes an
array; Azure and GCP (V1) nest them (`{ a: { b: '1' } }`).
The project `.env` is loaded before the functions are bundled. Azure and GCP still run the
vendored V1 server, which leaves text and octet-stream bodies unparsed; locally a handler
that reads the raw request stream for those two types gets an empty stream.
Expand Down
26 changes: 25 additions & 1 deletion src/functions/cloud-functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,16 @@ describe('CloudFunctions serve routing', () => {
expect(JSON.parse(response.body)).toEqual({ id: 'abc' });
});

it('keeps the query string flat, as deployed functions do', async () => {
writeFunctionFile('query.js', 'export default function query(request, response) { response.json(request.query); }');
const port = await freePort();

await new CloudFunctions(workspace).serve(port);
const response = await sendRequest(port, '/query?a[b]=1&list=1&list=2');

expect(JSON.parse(response.body)).toEqual({ 'a[b]': '1', list: ['1', '2'] });
});

it('answers a post request on an exact route', async () => {
writeFunctionFile('echo.js', 'export default function echo(request, response) { response.json({ method: request.method }); }');
const port = await freePort();
Expand Down Expand Up @@ -366,7 +376,7 @@ describe('CloudFunctions serve routing', () => {

it.each([
['application/json', '{"name":"launch","tags":["a","b"]}'],
['application/x-www-form-urlencoded', 'name=launch&tags[]=a&tags[]=b'],
['application/x-www-form-urlencoded', 'name=launch&tags=a&tags=b'],
])('hands a %s body to the handler as a parsed object', async (contentType, body) => {
writeFunctionFile('body.js', 'export default function body(request, response) { response.json({ body: request.body }); }');
const port = await freePort();
Expand All @@ -377,6 +387,20 @@ describe('CloudFunctions serve routing', () => {
expect(JSON.parse(response.body)).toEqual({ body: { name: 'launch', tags: ['a', 'b'] } });
});

it('keeps an urlencoded form flat, as deployed functions do', async () => {
writeFunctionFile('body.js', 'export default function body(request, response) { response.json({ body: request.body }); }');
const port = await freePort();

await new CloudFunctions(workspace).serve(port);
const response = await sendRequest(port, '/body', {
method: 'POST',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
body: 'a[b]=1&c=2&list=1&list=2',
});

expect(JSON.parse(response.body)).toEqual({ body: { 'a[b]': '1', c: '2', list: ['1', '2'] } });
});

it.each(['text/plain', 'application/octet-stream'])(
'hands a %s body over the 100kb parser default to the handler, as Lambda allows',
async (contentType) => {
Expand Down
3 changes: 2 additions & 1 deletion src/functions/cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ function applyRequestMiddleware(app: Express): void {
app.use(redirectLikeDeployedFunctions);
app.use(sendLikeDeployedFunctions);
app.use(express.json({ limit: DEPLOYED_PAYLOAD_LIMIT }));
app.use(express.urlencoded({ extended: true, limit: DEPLOYED_PAYLOAD_LIMIT }));
app.use(express.urlencoded({ extended: false, limit: DEPLOYED_PAYLOAD_LIMIT }));
app.use(express.text({ limit: DEPLOYED_PAYLOAD_LIMIT }));
app.use(express.raw({ limit: DEPLOYED_PAYLOAD_LIMIT }));
}
Expand Down Expand Up @@ -456,6 +456,7 @@ export class CloudFunctions {

const app = express();
app.disable('x-powered-by');
app.set('query parser', 'simple');
applyRequestMiddleware(app);
this.applyAppRouter(exactRouteResources, app);
this.applyAppRouter(dynamicRouteResources, app);
Expand Down
Loading