diff --git a/examples/PSCoreApp/MyHttpTrigger/run.ps1 b/examples/PSCoreApp/MyHttpTrigger/run.ps1 index 93ed1742..e61f034c 100644 --- a/examples/PSCoreApp/MyHttpTrigger/run.ps1 +++ b/examples/PSCoreApp/MyHttpTrigger/run.ps1 @@ -1,26 +1,33 @@ -# Invoked with Invoke-RestMethod: -# irm http://localhost:7071/api/MyHttpTrigger?Name=Tyler -# Input bindings are added via param block +# Trigger the function by running Invoke-RestMethod: +# (via get method): Invoke-RestMethod -Uri http://localhost:7071/api/MyHttpTrigger?Name=Joe +# (via post method): Invoke-RestMethod ` +# -Uri http://localhost:7071/api/MyHttpTrigger ` +# -Method Post ` +# -Body (ConvertTo-Json @{ Name="Joe" }) ` +# -Headers @{'Content-Type' = 'application/json' }` +# Input bindings are passed in via param block. param($req, $TriggerMetadata) -# If no name was passed by query parameter -$name = 'World' +# You can write to the Azure Functions log streams as you would in a normal PowerShell script. +Write-Verbose "PowerShell HTTP trigger function processed a request." -Verbose # You can interact with query parameters, the body of the request, etc. -if($req.Query.Name) { - $name = $req.Query.Name -} - -# you can write to the same streams as you would in a normal PowerShell script -Write-Verbose "Verbose $name" -Verbose -Write-Warning "Warning $name" +$name = $req.Query.Name +if (-not $name) { $name = $req.Body.Name } -# items in the pipeline get logged -$name +if($name) { + $status = 200 + $body = "Hello " + $name +} +else { + $status = 400 + $body = "Please pass a name on the query string or in the request body." +} -# You set the value of your output bindings by assignment `$nameOfOutputBinding = 'foo'` +# You associate values to output bindings by calling 'Push-OutputBinding'. Push-OutputBinding -Name res -Value ([HttpResponseContext]@{ - Body = @{ Hello = $name } - ContentType = 'application/json' + StatusCode = $status + Body = $body }) + diff --git a/src/PowerShell/PowerShellManager.cs b/src/PowerShell/PowerShellManager.cs index a2860839..12947b74 100644 --- a/src/PowerShell/PowerShellManager.cs +++ b/src/PowerShell/PowerShellManager.cs @@ -113,12 +113,14 @@ internal Hashtable InvokeFunction( { // Log everything we received from the pipeline and set the last one to be the ReturnObject Collection pipelineItems = _pwsh.InvokeAndClearCommands(); - foreach (var psobject in pipelineItems) + if (pipelineItems.Count > 0) { - _logger.Log(LogLevel.Information, $"OUTPUT: {psobject.ToString()}"); + foreach (var psobject in pipelineItems) + { + _logger.Log(LogLevel.Information, $"OUTPUT: {psobject.ToString()}"); + } + returnObject = pipelineItems[pipelineItems.Count - 1]; } - - returnObject = pipelineItems[pipelineItems.Count - 1]; } var result = _pwsh.AddCommand("Azure.Functions.PowerShell.Worker.Module\\Get-OutputBinding") diff --git a/src/Utility/TypeExtensions.cs b/src/Utility/TypeExtensions.cs index b469798b..8c3e01a2 100644 --- a/src/Utility/TypeExtensions.cs +++ b/src/Utility/TypeExtensions.cs @@ -70,7 +70,8 @@ public static object ToObject (this TypedData data) switch (data.DataCase) { case TypedData.DataOneofCase.Json: - return JsonConvert.DeserializeObject(data.Json); + var hashtable = JsonConvert.DeserializeObject(data.Json); + return new Hashtable(hashtable, StringComparer.OrdinalIgnoreCase); case TypedData.DataOneofCase.Bytes: return data.Bytes.ToByteArray(); case TypedData.DataOneofCase.Double: