If you use"app.use(range);"multiple times, the range request fails.
- Dominant language
- JavaScript
- Stars
- 51
- Forks
- 12
- PR merge metrics
- No merged PRs in 30d
Description
If you use"app.use(range);"multiple times, the range request fails.
```js
import Koa from "koa";
const app = new Koa();
import range from "koa-range";
import serveIndex from "koa2-serve-index";
import { publicpath } from "./publicpath.js";
app.use(range);app.use(range);
app.use(serveIndex(publicpath, { hidden: true }));
```
```text
GET / HTTP/1.1
Host: localhost:4000
Connection: keep-alive
sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"
cache-control: no-cache
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36
Accept: */*
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://localhost:4000/
Accept-Encoding: identity
Accept-Language: zh-CN,zh;q=0.9
Range: bytes=200-500
```
```text
HTTP/1.1 206 Partial Content
Access-Control-Allow-Origin: *
Accept-Ranges: bytes
Vary: Origin, Accept-Encoding
Content-Type: text/html; charset=utf-8
Content-Length: 301
ETag: "253d-9gLiUOyMqeHE6kv7oLd9+m5DLjI"
Content-Range: bytes 200-500/301
Date: Tue, 22 Jun 2021 04:37:05 GMT
Connection: keep-alive
Keep-Alive: timeout=5
```
The browser reports an error as follows.
```text
GET http://localhost:4000/ net::ERR_CONTENT_LENGTH_MISMATCH 206 (Partial Content)
```
Contributor guide
Research direction
Start by reproducing the request with the shown Koa setup and two app.use(range) registrations, using the supplied Range header and response. Trace the koa-range middleware behavior across both registrations and verify that the repeated setup no longer produces the reported 206 Content-Length mismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100