动态哈希定义有什么问题吗?为什么响应打印不能给我输出,但是当我给第一行发表评论时,响应打印发送输出
res.headers.each { |k, v| context.response.headers[k] = v }
context.response.print res.body
我的完整代码:https://github.com/codenoid/lemmehand/blob/master/server.cr 谢谢^^
答案 0 :(得分:2)
你想做什么?你有压缩流自动解压缩并按原样发送,而不更新编码头。
最小的工作示例:
server = HTTP::Server.new(port.to_i) do |context|
params = {} of String => String
context.request.query_params.each do |k, v|
params[k] = v
end
if params.has_key?("get")
HTTP::Client.get(params["get"]) do |res|
context.response.content_type = res.content_type.to_s
context.response.status_code = res.status_code
res.headers.each do |k, v|
next if k == "Content-Encoding"
next if k == "Content-Length"
next if k == "Transfer-Encoding"
context.response.headers[k] = v
end
context.response.print res.body_io.gets_to_end
end
else
context.response.content_type = "text/plain"
context.response.print "you must use GET method,ex. yourserver.com/?get=http://yoururl.com/"
end
end