oakserver / oak

A middleware framework for handling HTTP with Deno, Node, Bun and Cloudflare Workers 🐿️ 🦕

Home Page:https://oakserver.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duplicate content-length header when using FlashServer

meruiden opened this issue · comments

Whenever I serve static files using context.send, I get the content-length header twice:

with FlashServer:

> GET / HTTP/1.1
> Host: 0.0.0.0:4000
> User-Agent: curl/7.84.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Wed, 15 Feb 2023 16:49:48 GMT
< accept-ranges: bytes
< cache-control: max-age=0
< content-length: 132924
< content-type: text/html; charset=UTF-8
< etag: "2073c-XxoXS+dG5LRQ4oh0GCuk1l56ZH4"
< last-modified: Wed, 15 Feb 2023 15:05:28 GMT
< Content-Length: 132924

without FlashServer:

> GET / HTTP/1.1
> Host: 0.0.0.0:4000
> User-Agent: curl/7.84.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< accept-ranges: bytes
< cache-control: max-age=0
< content-length: 132924
< content-type: text/html; charset=UTF-8
< etag: "2073c-XxoXS+dG5LRQ4oh0GCuk1l56ZH4"
< last-modified: Wed, 15 Feb 2023 15:05:28 GMT
< vary: Accept-Encoding
< date: Wed, 15 Feb 2023 16:51:50 GMT

This results in both Postman and the DigitalOcean app platform refusing my responses.

Code to reproduce:

import { Application, Router, FlashServer } from "https://deno.land/x/oak@v11.1.0/mod.ts"
import { APP_HOST, APP_PORT } from "./config.js"

const app = new Application({ serverConstructor: FlashServer })
// const app = new Application()

const router = new Router()

app.use(router.routes())
app.use(router.allowedMethods())

app.use(async (context) => {
  await context.send({
    root: `${Deno.cwd()}/dist`,
    index: "index.html",
  })
})

console.log(`Listening on ${APP_HOST}:${APP_PORT} ...`)

await app.listen(`${APP_HOST}:${APP_PORT}`)

While I believe this is an underlying issue with Deno (see denolanddeno#18046) send() shouldn't really be setting content-length anymore as the Deno servers handle that now and send() setting it can only really end up leading to potential issues.