Skip to content

How to capture and respond to Kestrel BadHttpRequestException #25730

Answered by Tratcher
olavaukan asked this question in General
Discussion options

You must be logged in to vote

It seems that bad headers is such a low-level error it's handled deep inside Kestrel somewhere.

Correct, if the request is considered malformed the server will refuse it immideately without surfacing it to the application. That's because the server has no confidence that it can properly handle the semantics of the request if it's malformed.

I was rather shocked to find that a bad request was logged as Debug.

It's logged as debug because it's considered an external error that the application can't do anything about. We do something similar for client disconnect errors.

What you can do today to surface these errors is to selectively enable those server logs. You know it's:

  • "logger": "M…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@olavaukan
Comment options

@shirhatti
Comment options

Answer selected by olavaukan
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants