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

🚨 [BUG] UnsupportedWarning: Status message is not supported by HTTP/2 (RFC7540 8.1.2.4) #12134

Closed
1 task done
JakiChen opened this issue Oct 6, 2024 · 8 comments · Fixed by #12147
Closed
1 task done
Assignees
Labels
needs repro Issue needs a reproduction

Comments

@JakiChen
Copy link

JakiChen commented Oct 6, 2024

Astro Info

Astro                    v4.15.11
Node                     v20.18.0
System                   macOS (x64)
Package Manager          yarn
Output                   server
Adapter                  vercel
Integrations             @storyblok/astro
                         @astrojs/sitemap
                         astro-robots

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When https is enabled locally —— UnsupportedWarning: Status message is not supported by HTTP/2 (RFC7540 8.1.2.4)

截屏2024-10-06 23 31 36

What's the expected result?

  1. Make it clear whether this problem is a bug or real feedback, because this problem has not occurred in versions before 4.15.10.
  2. I hope to share the data method of await fetch() that cannot access the endpoint when https is enabled.

Currently, I can only deal with this problem by setting the dangerous behavior NODE_TLS_REJECT_UNAUTHORIZED to 0.

Link to Minimal Reproducible Example

https://owainmavxv.github.stackblitz.io

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Oct 6, 2024
@florian-lefebvre florian-lefebvre added the needs repro Issue needs a reproduction label Oct 7, 2024
Copy link
Contributor

github-actions bot commented Oct 7, 2024

Hello @JakiChen. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Oct 7, 2024
@bluwy
Copy link
Member

bluwy commented Oct 7, 2024

I'm guessing it's something to do with #12105

@JakiChen
Copy link
Author

JakiChen commented Oct 7, 2024

GitHub repository

To enable local https, you must first install config/certs/server.crt to macOS Keychain Access and set SSL to always allow

Currently, this bug only occurs in Astro version 4.15.11, and versions before 4.15.10 to 4.15.4 are all normal (so it is not clear whether this is a bug or a problem caused by my configuration)

@JakiChen
Copy link
Author

JakiChen commented Oct 7, 2024

heyyy, @bluwy

Currently, this issue has nothing to do with whether the local endpoint is used, but is related to enabling https through vite.server.https. This bug only exists in the latest version 4.15.11.

In addition, if you want to use await fetch() local endpoint locally, you must set

{
  "scripts": {
      "dev": "NODE_EXTRA_CA_CERTS=config/certs/rootCA.crt astro dev",
  }
}

to work properly (but the bug still exists)

@ascorbic ascorbic self-assigned this Oct 7, 2024
@JakiChen
Copy link
Author

JakiChen commented Oct 7, 2024

Add this NODE_OPTIONS="--trace-warnings" yarn dev

{
"scripts": {
    "dev": "NODE_EXTRA_CA_CERTS=config/certs/rootCA.crt NODE_OPTIONS=\"--trace-warnings\" astro dev",
    "start": "astro dev",
    "build": "astro check && astro build",
    "preview": "astro preview",
    "astro": "astro"
  },
}

for detail

 (node:28145) UnsupportedWarning: Status message is not supported by HTTP/2 (RFC7540 8.1.2.4)
    at statusMessageWarn (node:internal/http2/compat:115:13)
    at set statusMessage [as statusMessage] (node:internal/http2/compat:697:5)
    at writeWebResponse (file:///Users/JakiChen/Desktop/cloudflare/node_modules/astro/dist/vite-plugin-astro-server/response.js:49:21)
    at writeSSRResult (file:///Users/JakiChen/Desktop/cloudflare/node_modules/astro/dist/vite-plugin-astro-server/response.js:81:10)
    at handleRoute (file:///Users/JakiChen/Desktop/cloudflare/node_modules/astro/dist/vite-plugin-astro-server/route.js:214:9)
    at async run (file:///Users/JakiChen/Desktop/cloudflare/node_modules/astro/dist/vite-plugin-astro-server/request.js:40:14)
    at async runWithErrorHandling (file:///Users/JakiChen/Desktop/cloudflare/node_modules/astro/dist/vite-plugin-astro-server/controller.js:64:5)
    at async handleRequest (file:///Users/JakiChen/Desktop/cloudflare/node_modules/astro/dist/vite-plugin-astro-server/request.js:34:3)

@JakiChen
Copy link
Author

JakiChen commented Oct 8, 2024

Heyyyy, @ascorbic

fix: don't set statusMessage in HTTP/2 是这一个意思吗?还是说阉割了 HTTP/2 功能?

在使用 HTTP/2 协议时,不能直接设置 statusMessage。在 HTTP/1.1 中,响应状态码(如 200)通常会有一个状态消息(如 OK)。但在 HTTP/2 协议中,状态消息被移除了,只有状态码,而没有 statusMessage。

如果你的项目在使用 HTTP/2 协议时尝试设置 statusMessage,可能会导致这个警告或错误。也就是说,这种设置在 HTTP/2 下是无效的,因为 HTTP/2 的设计简化了响应格式,只关注状态码,而不再传递状态消息。

这个提示不代表项目不支持 HTTP/2,而是说 不应该在 HTTP/2 请求中尝试设置 statusMessage。如果你遇到了这个问题,可以考虑调整你的代码,不再手动设置 statusMessage,这样就可以避免这个问题。

@JakiChen
Copy link
Author

JakiChen commented Oct 8, 2024

在 Astro@4.15.12 的最新版本中好像依旧没有被修复, 现在只能靠自己手动去astro/dist/vite-plugin-astro-server/response.js(49:21)删除这一行?res.statusMessage = statusText;

async function writeWebResponse(res, webResponse) {
  const { status, headers, body, statusText } = webResponse;
  console.log(webResponse);
  const setCookieHeaders = Array.from(getSetCookiesFromResponse(webResponse));
  if (setCookieHeaders.length) {
    res.setHeader("set-cookie", setCookieHeaders);
  }
  const _headers = Object.fromEntries(headers.entries());
  if (headers.has("set-cookie")) {
    _headers["set-cookie"] = headers.getSetCookie();
  }
  console.log(res);
//   res.statusMessage = statusText;
  res.writeHead(status, _headers);
  if (body) {
    if (Symbol.for("astro.responseBody") in webResponse) {
      let stream = webResponse[Symbol.for("astro.responseBody")];
      for await (const chunk of stream) {
        res.write(chunk.toString());
      }
    } else if (body instanceof Readable) {
      body.pipe(res);
      return;
    } else if (typeof body === "string") {
      res.write(body);
    } else {
      const reader = body.getReader();
      res.on("close", () => {
        reader.cancel().catch(() => {
        });
      });
      while (true) {
        const { done, value } = await reader.read();
        if (done) break;
        if (value) {
          res.write(value);
        }
      }
    }
  }
  res.end();
}

不是很懂核心内部的代码核心,综合 ChatGPT 给的参考以及 console.log 出的结果应该是直接删除就好了(因为在HTTP/2中并不需要该值),希望 Astro 团队尽快修复,再次感谢 Astro 团队创造出如此容易上手理解的框架。

@ascorbic
Copy link
Contributor

ascorbic commented Oct 8, 2024

It's fixed in main, but I merged it after 4.15.12 was released. It will be in astro@4.15.13, which hasn't been released yet. You can see the release PR: #12148

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

Successfully merging a pull request may close this issue.

4 participants