【问题标题】:Anyone knows if vibe.d supports HTTP Byte-Range while serve static files?任何人都知道 vibe.d 在提供静态文件时是否支持 HTTP 字节范围?
【发布时间】:2016-06-29 13:35:41
【问题描述】:

我查看了vibe-d-0.7.28 的源代码,但fileserver.d 对此没有任何了解。实际上,sendFileImpl() 函数是该作业的主要实现,并且没有对字节范围标头的任何引用。

你知道这是否受支持或如何工作?

【问题讨论】:

  • 您是指 HTTP 范围请求(在 RGC 7233 中描述)吗? D中的“字节范围”也可以表示byte/ubyte的输入/输出范围,这是一个特定的数据结构。
  • 我的意思是 HTTP 字节范围 (RFC 7233)。很抱歉模棱两可。我会换个问题
  • 您绝对应该在vibe.d repo 提交增强请求(也称为问题);-)

标签: http web server d vibed


【解决方案1】:

因为#1634 这是可能的:

#!/usr/bin/env dub
/+ dub.sdl:
name "mini_vibed"
dependency "vibe-d" version="~>0.8.0-beta.4"
versions "VibeDefaultMain"
+/

import vibe.d;

shared static this()
{
    auto settings = new HTTPServerSettings;
    settings.port = 8080;

    auto router = new URLRouter;
    router.get("/full_file", (scope req, scope res) {
        auto inStream = openFile(__FILE_FULL_PATH__);
        res.bodyWriter.write(inStream);
    });
    router.get("/partial_file", serveStaticFile(__FILE_FULL_PATH__));
    router.get("*", (scope req, scope res) {
        res.writeBody("Please try /full_file or /partial_file");
    });

    listenHTTP(settings, router);
}

chmod +x 文件或使用dub --single 运行它。 您可以使用curl 进行测试:

curl --header "Range: bytes=0-200" localhost:8080/full_file
curl --header "Range: bytes=0-200" localhost:8080/partial_file

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    • 2010-10-07
    相关资源
    最近更新 更多