require 'rubygems'
require 'eventmachine'
require 'em-http-server'
class HTTPHandler < EM::HttpServer::Server
attr_accessor :filename, :filesize, :path
def process_http_request
#send file async
if @http_request_method.to_s =~ /GET/ && @http_request_uri.to_s.end_with?(filename)
send_data "HTTP/1.1 200 OK\n"
send_data "Server: XiaoMi\n"
send_data "Connection: Keep-Alive\n"
send_data "Keep-Alive: timeout=15\n"
send_data "Content-Type: application/octet-stream\n"
send_data "Content-Disposition: filename='#{filename}'\n"
send_data "Content-Length: #{filesize}\n"
send_data "\n"
streamer = EventMachine::FileStreamer.new(self, path)
streamer.callback {
# file was sent successfully
close_connection_after_writing
}
else
response = EM::DelegatedHttpResponse.new(self)
response.status = 200
response.content_type 'text/html'
response.content = "Package HttpServer<br>usage: wget http://host:port/#{filename}"
response.send_response
end
end
end
EM::run do
path = '/tmp/aaa.tar.gz'
EM::start_server("0.0.0.0", 8080, HTTPHandler) do |conn|
conn.filename = File.basename(path)
conn.filesize = File.size(path)
conn.path = path
end
end
Building native extensions. This could take a while...
ERROR: Error installing eventmachine:
ERROR: Failed to build gem native extension.
ERROR: Error installing ruby-debug:
The 'linecache' native gem requires installed build tools.
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
gem install eventmachine-win32
eventmachine --pre
gem install rdiscount –platform=ruby
gem install eventmachine
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有