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

Response data is stripped from certain status codes #8

Closed
mbcrawfo opened this issue Aug 26, 2017 · 2 comments
Closed

Response data is stripped from certain status codes #8

mbcrawfo opened this issue Aug 26, 2017 · 2 comments

Comments

@mbcrawfo
Copy link

I've skimmed through the server code and don't see anything that might be causing this, and when debug is enable the console reports that the response data is there, so I'm thoroughly stumped about the problem.

The example below should take a status code in the request body and echo it back to you using that status code for the response. For some status codes (e.g. 409 conflict) Postman reports that it gets nothing in the response body, and it's missing all of the headers that should normally be there (Access-Control-Allow-Origin, Content-Length, and Content-Type).

internal class Program
{
    public static void Main(string[] args)
    {
        var server = new Server("localhost", 8080, false, Handler, true);

        Console.ReadKey();
        server.Dispose();
    }

    private static HttpResponse Handler(HttpRequest request)
    {
        var bodyData = request.Data ?? new byte[0];
        var bodyString = Encoding.UTF8.GetString(bodyData);
        int statusCode;
        if (!int.TryParse(bodyString, out statusCode))
            statusCode = 404;

        return new HttpResponse(request, true, statusCode, null, "text/plain", bodyString, true);
    }
}
@jchristn
Copy link
Collaborator

Hi @mbcrawfo it looks like this is the behavior anytime a status code is used that isn't accounted for in BuildErrorResponse and SendResponse. I tried with 200, 201, 400, 404, etc, and they returned the correct headers. Can you confirm that is the case? If so, I can add 409 an any other status codes you wish to use that I may have missed. Thanks!

@jchristn
Copy link
Collaborator

Hi @mbcrawfo I just committed a fix and also updated NuGet (see aeb7081) - could you re-open if this doesn't work as expected for you? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants