Skip to content

HTTP input binding Body property type depends on the request body content #241

@AnatoliB

Description

@AnatoliB

When a function is invoked via an HTTP trigger, the $HttpRequest.Body property type depends on the actual request body content. For example, when the request body contains a simple string like Hello, $HttpRequest.Body will contain 'Hello' as a string. However, if the request body contains anything that could be interpreted as a syntactically valid JSON (e.g. {"Hello":"world"}), $HttpRequest.Body will contain the result of JSON deserialization (@{ Hello = 'world' } as a hashtable), even when the request explicitly specifies Content-Type: text/plain. This implicit JSON deserialization may be convenient in many cases, but will cause confusion and unexpected function behavior changes depending on the client input.

Consider following more deterministic rules, such as:

  • If the request has Content-Type: application/json explicitly specified:
    • If the body contains a valid JSON, deserialize and assign the result to $HttpRequest.Body
    • If the body does not contain a valid JSON, respond with 400 (BadRequest) and don't invoke the function code
  • If the request has Content-Type: text/plain explicitly specified:
    • Pass the body to $HttpRequest.Body as is, don't even verify JSON syntax or attempt to deserialize
  • etc.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions