-
Notifications
You must be signed in to change notification settings - Fork 110
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
Default IsProblem
returning false for a 404
#158
Comments
Honestly I'd be fine with just removing the |
Actually, I'm not even sure this warrants a change at all. If you're proxying a response from upstream and that response had an empty body, it does make sense that YARP would set |
Or you could customize it on the YARP-side by adding a response transform 😅 |
Good point about creating a response transform! I was hoping that the dev ux was such that dropping in ProblemDetailsMiddleware and YARP together would "just work". It took a little while to find that it was the I also suspect I'm a little on the OCD spectrum when it comes to even verifying that a ProblemDetails response is being returned in this case. I strongly suspect that my peers in the software house I work for would not have noticed :-0. Hence the desire for out-of-the-box experience to "just work"
Yeah that's what I've done but I felt sad that I had to duplicate the existing default code, particularly the public static void ConfigureProblemDetails(ProblemDetailsOptions c) {
// snip
c.IsProblem = IsProblem;
bool IsProblem(HttpContext context) {
// note: this function is a copy of https://github.com/khellang/Middleware/blob/70ac2fb251baabc750c5a7e40e619cfc59c12e1f/src/ProblemDetails/ProblemDetailsOptionsSetup.cs#L79-L97
// we're having to copy it to modify the check for ContentLength as YARP is setting ContentLength to zero
// even though it has not started sending the response yet
if (!IsProblemStatusCode(context.Response.StatusCode)) {
return false;
}
// if (context.Response.ContentLength.HasValue)
if (context.Response.ContentLength > 0) {
return false;
}
if (string.IsNullOrEmpty(context.Response.ContentType)) {
return true;
}
return false;
}
bool IsProblemStatusCode(int? statusCode) {
return statusCode switch
{
>= 600 => false,
< 400 => false,
null => false,
_ => true
};
}
} |
Yeah, I get that, but this code will never change, so I don't think it would be a big maintenance burden. If I were you, I'd just replace the entire |
:-) Yes making |
Sure, go for it! 😃 |
If I bump the minor version (eg 6.3.0 -> 6.4.0), will that trigger the publish of the nuget package? |
No, I haven't gotten around to automatic push to NuGet, so have to push the binaries manually still :( |
I'm using YARP to proxy requests to an azure functions app. When the functions app returns a 404, the YARP middleware is setting
Response.ContentLength
to a value of0
even thoughResponse.HasStarted
is returningfalse
at this point in the pipeline.The consequence is the default
IsProblem
function is returningfalse
.According to comment you made here, the check for
ContentLength
is redundant. So would it be possible to change the check to the following?:For reference, the current code:
Happy to create a PR for this
The text was updated successfully, but these errors were encountered: