Giter Club home page Giter Club logo

koa-range's People

Contributors

masx200 avatar mreinstein avatar yorkie avatar zetatwo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

koa-range's Issues

transfer to org

transfer to me and i can transfer it in if you can't transfer it in yourself

If you use"app.use(range);"multiple times, the range request fails.

If you use"app.use(range);"multiple times, the range request fails.

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 }));
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

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.

GET http://localhost:4000/ net::ERR_CONTENT_LENGTH_MISMATCH 206 (Partial Content)

If the starting point of the range request is greater than the maximum length of the content, the response status 416 shall be returned.

If the starting point of the range request is greater than the maximum length of the content, the response status 416 shall be returned.

GET / HTTP/1.1
Host: localhost:4000
Connection: keep-alive
Cache-Control: no-cache
sec-ch-ua: " Not;A Brand";v="99", "Microsoft Edge";v="91", "Chromium";v="91"
DNT: 1
accept-language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
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.114 Safari/537.36 Edg/91.0.864.54
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
upgrade-insecure-requests: 1
if-none-match: "253b-oDUrS8IQyJRM9EiG2CmtiW6ahlM"
range: bytes=9999999-
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://localhost:4000/
Accept-Encoding: identity


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: -9990468
ETag: "253b-pRYhHemHVMhhBMOOkvWAjABIxIE"
Content-Range: bytes 9999999-9530/9531
Date: Tue, 22 Jun 2021 05:59:36 GMT
Connection: keep-alive
Keep-Alive: timeout=5

I found that some video player clients will send out requests for video files beyond the scope.
E.g. PotPlayer

Support for koa@2

As the title says, would be great to have a branch (and npm version published) with support for koa version 2.

I'm preparing a PR

Doesn't work with chrome on video files

With small video (mp4) files, chrome has no issues. However if I use a 34 mbish sort of a video file. It will sometimes play the first 2 secs, like (5%) of the file or just stay stuck in limbo and not respond to the request. The code I have is pretty simple:

import fs from 'fs';
import Koa from 'koa';
import koaLogger from 'koa-logger';
import koaRange from 'koa-range';

const app = new Koa();
const router = new koaRouter();

app
  .use(koaLogger())
  .use(koaRange)


   /*
   * TEST VIDEO STREAM
   */
  router.get('/test', async (ctx, next) => {
    ctx.type = 'video/mp4';
    ctx.body = fs.createReadStream(__dirname + '/test.mp4');
  });

app
  .use(router.routes())
  .use(router.allowedMethods())
  .listen('3000');

It works fine on firefox, but I think firefox doesn't even use ranges for video. It also works fine when koaRange is removed as a middleware but then it would not seek, as expected. Using the latest version of koa and koa-range

slow with very large files

I'm using koa-range via local-web-server to serve up small slices (e.g. 12kb) of a large (12GB) file. The response time is very slow - on the order of 30+ seconds.

I'm not at all familiar with node, but I'm somewhat suspicious of this line, which seems to read and discard from the very beginning of the file.

rawBody = rawBody.pipe(slice(start, end + 1));

That rawBody seems to come from this line in koa-send:

ctx.body = fs.createReadStream(path)

It might be better if we can find a way to stream only the requested portion of the data , rather than streaming the entire stream through the slice function.

e.g. somewhere in koa-send:

ctx.body = fs.createReadStream(path, { start, end });

Giving an error with empty body

I'm using koa-range with koa-better-static, and the user is making a request with

if-modified-since:Fri, 01 Apr 2016 18:21:16 GMT
range:bytes=15110-6381395

koa-better-static returns 304 NOT MODIFIED with an empty body because the file has not been modified since that date, but now koa-range tries to access this.body.length which throws an error as its dereferencing undefined

conform to RFC7233 more thoroughly

I've read through rfc7233, and I'm going to attempt re-writing koa-range to be more compliant with the spec. There are a lot of weird edge cases having to do with handling the presence of other http headers (e.g., If-Match, If-Range, etc.)
I'd also like to modernize the stream handling since we're relying on ancient node-isms.

I'd also like to drop the old unsupported versions of node (<= v12) but I'm not sure when to do this. It would be really nice to have as many fixes in place before dropping node versions.

`Content-Length` is wrong when full content is smaller than the requested Range

> User-Agent: facebookexternalhit/1.1
> Accept: */*
> Accept-Encoding: deflate, gzip
> Range: bytes=0-524287
>
< HTTP/1.1 206 Partial Content
< Date: Sat, 24 Feb 2018 06:27:21 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 524288
< Connection: keep-alive
< Accept-Ranges: bytes
< Content-Range: bytes 0-524287/12338
< x-readtime: 52

The Content-Length should be the content's real size(https://github.com/koajs/koa-range/blob/master/index.js#L80) will be better when full content is smaller than the requested Range.

Also see: restlet/restlet-framework-java#604

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.