Skip to content

HttpRequestMessageExtensions.CreateResponse<T> should not accept T==HttpStatusCode #67

@ghost

Description

In an audit of our code base, we found that there were many calls that looked like:
return Request.CreateResponse(HttpStatusCode.NotFound);
that, due to a refactor, were actually resolving to this:
HttpResponseMessage CreateResponse<T>(this HttpRequestMessage request, T value)
This would make the service return a 200 with a body that says "NotFound". This is clearly not the intent of the programmer.

Possible solutions would be:

  1. Add a more specific extension that specifically targets HttpStatusCode (e.g.System.Net.Http.Formatting has one)
  2. Throw if T is HttpStatusCode

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions