dtc99987 2014-03-12 15:28
浏览 24

webserver提供延迟的文件请求

I'm trying to figure out if it is possible to configure a webserver so that requests for files will be served with a delay. So for example if i were to serve this file http://www.example.url/picture.jpg, i want the data transfer to start only 2 seconds after the request has been made... or any other arbitrary number. The important bit is that this should work independent from how the file is accessed, so just an html solution isn't workable.

I have asked around on superuser.com and people there recommended me to look into perl or php to put something together that way that could provide me with the functionality i need. Now i do not have any experience with any of these languages mentioned but i'm assuming it wouldn't be too complicated to put something together like that, my question is... can someone help me get started?

Thanks for your time.

  • 写回答

1条回答 默认 最新

  • dqy92287 2014-03-14 10:43
    关注

    If you are using Apache2 with mod_perl, then you could use one of the handlers to do this filtering. However, even with the below code as an example, you're going to need to be familiar with both perl and server configuration:

    package ImgPause;
    
    use Apache2::RequestRec();
    
    use Apache2::Const -compile => qw(FORBIDDEN OK);
    
    use strict;
    use warnings;
    
    our %images = (
        '/adesert.jpg'    => 4,
        '/afish.jpg'      => 4,
        '/aflower.jpg'    => 4,
        '/ahouse.jpg'     => 4,
        '/akoala.jpg'     => 4,
        '/apenguin.jpg'   => 4,
        '/atulip.jpg'     => 5,
    )
    
    sub handler {
        my $r = shift;
    
        my $host = $r->header_in('Host');
        my $uri = $r->uri;
    
        if ($images{$uri}) {
            sleep $images{$uri};
        }
    
        return Apache2::Const::OK;
    }
    
    1;
    
    __END__
    
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码