Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal API default content-type for bad request is application/octect-stream , chrome returns ERR_INVALID_RESPONSE #1923

Closed
1 task
sebastienlabine opened this issue Jan 3, 2025 · 2 comments
Assignees
Labels
bug This issue is a bug. closed-for-staleness module/lambda-client-lib needs-reproduction This issue needs reproduction. p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to close soon in 7 days.

Comments

@sebastienlabine
Copy link

sebastienlabine commented Jan 3, 2025

Describe the bug

When using the minimal api extension method
builder.Services.AddAWSLambdaHosting(LambdaEventSource.ApplicationLoadBalancer)
the response from our lambda when returning a bad request return (NotFound(), BadRequest(), Unauthorized()) has the content-type application/octect-stream which should be application/json.

This creates a ERR_INVALID_RESPONSE on chrome

image
image

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The content type returned should be application/json

Current Behavior

The content type returned is application/octect-stream

Reproduction Steps

  1. Create a minimal API setup and add the AddAWSLambdaHosting(LambdaEventSource.ApplicationLoadBalancer)
  2. Create a controller and return a 400,500 status code.
  3. Test locally and observe the correct headers
  4. Deploy the lambda and observe the wrong content-type

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

Amazon.Lambda.AspNetCoreServer.Hosting1.7.3

Targeted .NET Platform

.NET Core 8

Operating System and version

Windows 10

@sebastienlabine sebastienlabine added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 3, 2025
@ashishdhingra ashishdhingra self-assigned this Jan 3, 2025
@ashishdhingra ashishdhingra added needs-reproduction This issue needs reproduction. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Jan 3, 2025
@ashishdhingra
Copy link
Contributor

@sebastienlabine Good afternoon. Somehow I'm unable to reproduce the issue using the dotnet new serverless.AspNetCoreMinimalAPI template and adding below Error route to the generated CalculatorController:
Controllers\CalculatorController.cs

using Microsoft.AspNetCore.Mvc;

namespace MinimalApiOnLambda.Controllers;

[ApiController]
[Route("[controller]")]
public class CalculatorController : ControllerBase
{
    private readonly ILogger<CalculatorController> _logger;

    public CalculatorController(ILogger<CalculatorController> logger)
    {
        _logger = logger;
    }

...
...

    [HttpGet("error")]
    public IActionResult Error()
    {
        return StatusCode(500);
    }
}

Program.cs

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllers();

// Add AWS Lambda support. When application is run in Lambda Kestrel is swapped out as the web server with Amazon.Lambda.AspNetCoreServer. This
// package will act as the webserver translating request and responses between the Lambda event source and ASP.NET Core.
builder.Services.AddAWSLambdaHosting(LambdaEventSource.ApplicationLoadBalancer);

var app = builder.Build();

app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();

app.MapGet("/", () => "Welcome to running ASP.NET Core Minimal API on AWS Lambda");

app.Run();

Deploying above code still creates a RestApi in API Gateway. Followed instructions at Lambda functions as targets for Application Load Balancers to configure Serverless Web API Lambda function with ALB (it basically mentions creating ALB and adding Lambda ALB trigger). After deployment, we would need to add security group inbound rule to allow HTTP 80 or HTTPS 443 ports.

Requesting Error endpoint using ALB DNS name (e.g. http://testminimalapialb-130218691.us-east-2.elb.amazonaws.com/calculator/error) gives the below response:

{"type":"https://tools.ietf.org/html/rfc9110#section-15.6.1","title":"An error occurred while processing your request.","status":500,"traceId":"00-36059fcd25a659e4e3509775dce94012-f18854f5cf1d8224-00"}

Screenshot 2025-01-03 at 3 04 42 PM
Notice that the content type is application/problem+json; charset=utf-8.

Please share the minimal reproducible code solution along with steps to reproduce the issue.

Thanks,
Ashish

@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Jan 3, 2025
Copy link
Contributor

This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closed-for-staleness module/lambda-client-lib needs-reproduction This issue needs reproduction. p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to close soon in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants