Alright, so I ran some test cases and did indeed find some interesting results.
Setup
Given the following _redirects
record for a splat-injected rewrite:
/test/* /.netlify/functions/test-rewrite-to-function?parm=:splat 200
I ran the following tests (using my favorite CLI tool, httpie:
Standard:
http https://sun.sargesites.com/test/hello
Which yielded the following object for the event
argument to the function (I removed some of the headers for brevity; unimportant to test):
{
"path": "/test/hello",
"httpMethod": "GET",
"headers": {
"accept": "*/*",
"accept-encoding": "gzip",
"connection": "keep-alive",
"user-agent": "HTTPie/2.1.0",
"via": "https/1.1 Netlify[840aa3b4-795a-4b07-aa09-e6f488912ae4] (ApacheTrafficServer/7.1.11)",
"x-cdn-domain": "global.netlify.com",
"x-country": "US",
"x-forwarded-proto": "https",
},
"queryStringParameters": {},
"multiValueQueryStringParameters": {},
"body": "",
"isBase64Encoded": true
}
So there was actually no query string data when the Function was called, but the initial path
is reported. Okay moving forward.
Call direct with parms:
http https://jonsdomain.com/.netlify/functions/test-rewrite-to-function?parm=hello
Which yielded the following object for the event
argument to the function (I removed some of the headers for brevity; unimportant to test):
{
"path": "/.netlify/functions/test-rewrite-to-function",
"httpMethod": "GET",
"headers": {
"accept": "*/*",
"accept-encoding": "gzip",
"user-agent": "HTTPie/2.1.0",
"via": "https/1.1 Netlify[840aa3b4-795a-4b07-aa09-e6f488912ae4] (ApacheTrafficServer/7.1.11)",
"x-country": "US",
"x-forwarded-proto": "https",
},
"queryStringParameters": {
"parm": "hello"
},
"multiValueQueryStringParameters": {
"parm": [
"hello"
]
},
"body": "",
"isBase64Encoded": true
}
So the path matches the origin request and the query string parameter was parsed into event.queryStringParameters
so the standard Lambda system works! Thatâs good, at least
Call direct with empty param:
http https://jonsdomain.com/.netlify/functions/test-rewrite-to-function?parm=
Which yielded the following object for the event
argument to the function (I removed some of the headers for brevity; unimportant to test):
{
"path": "/.netlify/functions/test-rewrite-to-function",
"httpMethod": "GET",
"headers": {
"accept": "*/*",
"accept-encoding": "gzip",
"connection": "keep-alive",
"user-agent": "HTTPie/2.1.0",
"via": "https/1.1 Netlify[c9c5b509-8a45-4a7c-a4b5-03f81d19d15f] (ApacheTrafficServer/7.1.11)",
"x-cdn-domain": "global.netlify.com",
"x-country": "US",
"x-forwarded-proto": "https",
},
"queryStringParameters": {
"parm": ""
},
"multiValueQueryStringParameters": {
"parm": [
""
]
},
"body": "",
"isBase64Encoded": true
}
Just wanted to run this test to see how the function input is given when the query string parameter is present but empty. This is important, but the key takeaway here is that the event.queryStringParameters
does have the parm in it, even though itâs empty.
Conclusions:
- I think the
path
parameter does accurately reflect the path specified in the origin request, both for standard Function calls and Function calls via Rewrite proxy
- For whatever reason, the 200-based Rewrite operation ignores query parameters altogether. At first I thought it just wasnât hydrating the
:splat
but as test #3 shows, even if the :splat
was empty, the ?parm=
part would still show in event.queryStringParameters
â this indicates to me that the Rewrite engine is actually dropping the the query-string component altogether (the ?
and everything after), which seems odd. @Dennis or @Scott do either of you have knowledge on why that could be?