Skip to content

Custom Handler how to return specific http Statuscodes and Headers #10987

Closed
@j-nierop

Description

@j-nierop

Is your question related to a specific version? If so, please specify:

No

What language does your question apply to? (e.g. C#, JavaScript, Java, All)

Rust/GO Custom Handler

Question

I want to know how I can tell the Function Host to return a specific Http statuscode and/or Http Headers to the caller of the azure function. I understand that when using "enableForwardingHttpRequest": true custom handler receives the same request that the host received and that caller receives the same response that the custom handler created (including status code and headers). However I want to use Application Insights for logging and see the request meta data generated by the function host such as the InvocationId and Claims related to the function key that was used so that I can identify which key was used which means I need to use "enableForwardingHttpRequest": false. The issue is that I can't seem to find any sources explaining how to tell the function host to return a specific http status code or headers with the response. In other words, what response does my custom handler need to return so that caller of the function sees a response with specific http status code and headers.

I understand that the contents of the body of the response that the caller of the function sees can be set by making the custom handler respond with the following application/json status code 200 response:

{
    "Outputs": {},
    "Logs": [
        "Log message 1",
        "Log message 2",
    ],
    "ReturnValue": "<body of response that the caller receives>",
}

Simply put: What would I need to change in the json response above so that the called receives for example an http 400 Bad Request and perhaps a specific set of Headers? Or am I missing something obvious?

I would also really appreciate it if someone can point me to some resources I could consult.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions