Skip to content

Content-Type header on output build unconditionally stuck as octet-stream #9514

@Schachte

Description

@Schachte

Astro Info

Astro                    v4.0.3
Node                     v20.9.0
System                   macOS (arm64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             @astrojs/react
                         @astrojs/mdx

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

All

Describe the Bug

I'm trying to return static JSON from my endpoint and my browser just downloads the contents as a file. The response headers are not being interpreted as application/json, but as octet-stream.

This isn't problematic when running the dev server, only on the output build. I can repro with both http-server locally and on Cloudflare pages post-deployment.

< HTTP/1.1 200 OK
< accept-ranges: bytes
< cache-control: max-age=3600
< last-modified: Sun, 24 Dec 2023 23:14:31 GMT
< etag: W/"36877538-13-2023-12-24T23:14:31.824Z"
< content-length: 13
< content-type: application/octet-stream
< Date: Sun, 24 Dec 2023 23:17:14 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
<
* Connection #0 to host localhost left intact
{"hi":"test"}%

Note the content-type: application/octet-stream which is telling the browser to download instead of render as JSON. I followed the docs directly, but also tried adding headers. Neither approach worked for me:

export async function GET({ params, request }) {
  const headers = new Headers({
    "Content-Type": "application/json; charset=utf-8",
  });
  return new Response(JSON.stringify({ hi: "test" }), { headers, status: 200 });
}

inside pages/release.js. I can repro locally like so:

  1. Build the above route
  2. Run the build with npm run build
  3. Serve static files locally http-server dist/
  4. Visit http://localhost:4321/release and note the response headers not being application/json

Am I just missing something obvious here?

What's the expected result?

The headers should be JSON and JSON should be served and rendered by the browser. Applications like CURL should properly return the expected content-type header as application/json, etc.

Link to Minimal Reproducible Example

N/A

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageIssue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions