Azure functions & HTTP OPTIONS request

Kermit754

I want an existing application (which I do not control) to send information to an Azure function.

The application first sends a HTTP OPTIONS request, and will then regularly send HTTP POST messages.

The problem I have is that the application expects a header "Allow : POST,OPTIONS" in the response from the Azure function on the OPTIONS request. If the header is not present, it will not continue (instead, it throws an error : 'POST is not allowed')

When trying to set the header in Azure functions, I get the following error message

System.Net.Http: Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.

I did enable CORS for all locations, and allowed all methods in the configuration.

module.exports = function (context, req) 
{
    //context.log('JavaScript HTTP trigger function processed a request.');

    if (req.method == "OPTIONS") 
    {
            context.res = 
            {
                body: "",
                headers: 
                { 
                    //"Access-Control-Allow-Methods" : "POST,OPTIONS",
                    "allow" : "POST,OPTIONS"
                },
                status: 200,
            };
    }
    context.done();
}

The specification say that the Allow header should be set for a 405 response. If the header is empty, nothing is allowed. However, there is no logic defined for when the header is not present at all.

Is there a method through which I can send this header in response to the HTTP OPTIONS ?

Jerry Liu

The error is expected. Function runtime is based on C#, when the response tries to add the Allow header, underlying C# code checks its name. It's by design that Allow is a read-only header in HttpContentHeaders hence we can't add it in HttpResponseHeaders.

Here are two workarounds for you to refer.

  1. Use a custom header name like Allow-Method.

  2. Create a new Function app, it uses Function runtime 2.0 by default, where we can set Allow header.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Cloud Functions times out when calling an external HTTP with a POST request

分類Dev

Azure Functions Proxy - unable to set a HTTP header if value contains JSON

分類Dev

Azure DocumentDB - The MAC signature found in the HTTP request is not the same as the computed signature

分類Dev

Azure Functions: CORS: How to support "Access-Control-Allow-Credentials" header AND OPTIONS pre-flight?

分類Dev

Azure Mobile app ServicesからHTTP(Azure Functions)を呼び出す方法は?

分類Dev

Context Broker Preflight OPTIONS request

分類Dev

Preflight OPTIONS request with Faraday gem

分類Dev

HTTP応答でHTMLファイルを返す方法(Azure-Functions)

分類Dev

Create a new user in Azure Active Directory (B2C) with Graph API, using http post request

分類Dev

Can I transform this C# http POST request to Azure Computer Service to JavaScript?

分類Dev

Azure FunctionsのDI

分類Dev

Azure FunctionsのDI

分類Dev

Azure FunctionsのDI

分類Dev

Developing Azure functions locally

分類Dev

Azure functions runtime configuration

分類Dev

Azure Functions return IQueryable

分類Dev

Azure Functions Traffic Manager

分類Dev

Http Request in TypeScript

分類Dev

Http Request in TypeScript

分類Dev

Cancel pending $http request

分類Dev

"Resend" an Angular $http request

分類Dev

NodeJS http request handler

分類Dev

Running a HTTP request with rails

分類Dev

Http request document head

分類Dev

http post request curl

分類Dev

Bash aliases/functions and command line options

分類Dev

Multiple Aggregate functions in one request

分類Dev

How to make httpd response 200 for options request?

分類Dev

URLがRequest型であり、Angularの文字列ではない場合、http.requestはoptionsパラメーターを考慮しません。

Related 関連記事

  1. 1

    Cloud Functions times out when calling an external HTTP with a POST request

  2. 2

    Azure Functions Proxy - unable to set a HTTP header if value contains JSON

  3. 3

    Azure DocumentDB - The MAC signature found in the HTTP request is not the same as the computed signature

  4. 4

    Azure Functions: CORS: How to support "Access-Control-Allow-Credentials" header AND OPTIONS pre-flight?

  5. 5

    Azure Mobile app ServicesからHTTP(Azure Functions)を呼び出す方法は?

  6. 6

    Context Broker Preflight OPTIONS request

  7. 7

    Preflight OPTIONS request with Faraday gem

  8. 8

    HTTP応答でHTMLファイルを返す方法(Azure-Functions)

  9. 9

    Create a new user in Azure Active Directory (B2C) with Graph API, using http post request

  10. 10

    Can I transform this C# http POST request to Azure Computer Service to JavaScript?

  11. 11

    Azure FunctionsのDI

  12. 12

    Azure FunctionsのDI

  13. 13

    Azure FunctionsのDI

  14. 14

    Developing Azure functions locally

  15. 15

    Azure functions runtime configuration

  16. 16

    Azure Functions return IQueryable

  17. 17

    Azure Functions Traffic Manager

  18. 18

    Http Request in TypeScript

  19. 19

    Http Request in TypeScript

  20. 20

    Cancel pending $http request

  21. 21

    "Resend" an Angular $http request

  22. 22

    NodeJS http request handler

  23. 23

    Running a HTTP request with rails

  24. 24

    Http request document head

  25. 25

    http post request curl

  26. 26

    Bash aliases/functions and command line options

  27. 27

    Multiple Aggregate functions in one request

  28. 28

    How to make httpd response 200 for options request?

  29. 29

    URLがRequest型であり、Angularの文字列ではない場合、http.requestはoptionsパラメーターを考慮しません。

ホットタグ

アーカイブ