Aws-lambda-dotnet: Difference between Kestrel and Lambda response

Created on 26 May 2018  路  2Comments  路  Source: aws/aws-lambda-dotnet

If you make an AJAX request from jQuery 3.3.1 to an API endpoint, without specifying the content-type, e.g. when making a DELETE request to /item/{id} which simply returns a 200 OK, then the response from Lambda will include the content-type application/json, while Kestrel will exclude that response header.

This can be a problem for apps using jQuery to make AJAX requests, because jQuery doesn't expect the content-type application/json in the response header and thus jQuery never calls the done callback.

My 'hack' around this issue is to set the content-type to text/plain in the AJAX request. That way jQuery will call the done callback function even though the content-type is application/json

Is this by design or a bug? I couldn't find anything in API Gateway regarding default content-type in responses.

Thanks.

bug

All 2 comments

Not by design. I found out if we don't return back the content type header in the headers collection sent to API Gateway then API Gateway will return back the default content-type of application/json. I checked in a https://github.com/aws/aws-lambda-dotnet/commit/f7274ca028b2532b1f92d30b151fdd4f6d7f7983 on the dev branch for the next release that will add content-type with a value of null to the headers collection when no content-type is returned from ASP.NET Core.

Thanks for reporting the issue.

Version 2.0.4 was released with this change. Thanks for reporting the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ljacobsson picture ljacobsson  路  7Comments

briancullinan picture briancullinan  路  7Comments

scionwest picture scionwest  路  4Comments

jakejscott picture jakejscott  路  6Comments

lehoangphan picture lehoangphan  路  4Comments