Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Httptrigger] Add support for nullable types in query string #895

Open
Francisco-Gamino opened this issue Nov 18, 2022 · 1 comment
Open
Assignees
Milestone

Comments

@Francisco-Gamino
Copy link
Contributor

Currently, for an httptrigger function, null or empty values cannot be passed in the query string.

Repro: create a default http trigger function. The name of my function is ProcessData. In the run.ps1 file, define the following:

using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

Write-Host "PowerShell HTTP trigger function processed a request."

# Update req_query with the query of the request
$req_query = @{
    name = $Request.query.name
    cost = $Request.query.cost
}

Write-Host $req_query

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = $req_query
})

The $uri below has a null value for name in the query string.

$uri = 'http://localhost:2056/api/ProcessData?name&cost=10'
$result = irm -Uri $request -Method Post

However, the $Request.query.name property will not be available. By default, the Functions Host, drops any values that are null or empty in the query string. To support this functionality, we need to add the UseNullableValueDictionaryForHttp capability to the PowerShell language worker, so the Functions Host sets the values in the query string as a nullable type. After enabling the capability, we need to add code to the PowerShell language worker to parse the rpcHttp.NullableQuery and headers. This will be a breaking change, so we will not fix this until we enable support for PowerShell 7.4.

As a workaround, the user can use the $TriggerMetadata[$keyName] to retrieve the query property. This is what the function will look like with the workaround which works as expected.

using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

Write-Host "PowerShell HTTP trigger function processed a request."

# Update req_query with the query of the request
$req_query = @{
   name = $TriggerMetadata["name"]
   cost = $TriggerMetadata["cost"]
}

Write-Host $req_query

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = $req_query
})
@Francisco-Gamino
Copy link
Contributor Author

We should consider fixing this for PowerShell 7.4 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant