denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.82k stars 5.38k forks source link

Cannot set custom `statusText` on `Response` #14822

Closed sntran closed 1 year ago

sntran commented 2 years ago

Describe the issue

A Response with custom statusText does not actually send that statusText to the client.

Steps to reproduce

deno run --allow-net the following sample web server with small modification to the returning Response:

// Start listening on port 8080 of localhost.
const server = Deno.listen({ port: 8080 });
console.log(`HTTP webserver running.  Access it at:  http://localhost:8080/`);

// Connections to the server will be yielded up as an async iterable.
for await (const conn of server) {
  // In order to not be blocking, we need to handle each connection individually
  // without awaiting the function
  serveHttp(conn);
}

async function serveHttp(conn: Deno.Conn) {
  // This "upgrades" a network connection into an HTTP connection.
  const httpConn = Deno.serveHttp(conn);
  // Each request sent over the HTTP connection will be yielded as an async
  // iterator from the HTTP connection.
  for await (const requestEvent of httpConn) {
    // The native HTTP server uses the web standard `Request` and `Response`
    // objects.
    const body = `Your user-agent is:\n\n${
      requestEvent.request.headers.get("user-agent") ?? "Unknown"
    }`;
    // The requestEvent's `.respondWith()` method is how we send the response
    // back to the client.
    requestEvent.respondWith(
      new Response(body, {
        status: 211,
        statusText: "Custom",
      }),
    );
  }
}

Expected Result

When curl -I "http://localhost:8080", a 211 Custom status is returned.

Actual Result

211 <none> is returned.

Environment

OS: Mac 12.3 Deno: 1.22

nyzd commented 2 years ago

It seems http lib doesn't support statusText or something like this, so They just use the custom status, not statusText.

aapoalas commented 2 years ago

https://developer.mozilla.org/en-US/docs/Web/API/Response/statusText#value

Note that HTTP/2 does not support status messages.

sntran commented 2 years ago

https://developer.mozilla.org/en-US/docs/Web/API/Response/statusText#value

Note that HTTP/2 does not support status messages.

This assumes that Response is strictly for HTTP (and HTTP/2).

For example, I have an NNTP library that uses Response as well, and if Response class has statusText, I don't see a reason not to use it.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

sant123 commented 2 years ago

I think this should not be stale 🤔

crowlKats commented 1 year ago

This isnt possible due to https://github.com/hyperium/http/issues/345#issuecomment-558763905

crowlKats commented 1 year ago

Closing due to the aforementioned limitation.