ruby-on-rails – 使用带有Rails的X-Accel-Redirect创建POST请求?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了ruby-on-rails – 使用带有Rails的X-Accel-Redirect创建POST请求?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1779字,纯文字阅读大概需要3分钟。
内容图文
我正在使用rails 4,我正在向另一台服务器代理GET请求,如下所示:
def proxy_video(path)
self.status = 200
response.headers["X-Accel-Redirect"] = "/proxy/#{path}"
render text: 'ok'
end
在我的nginx配置中,我有这个:
location ~* ^/proxy/(.*?)/(.*) {
internal;
resolver 127.0.0.1;
# Compose download url
set $download_host $1;
set $download_url http://$download_host/$2;
# Set download request headers
proxy_set_header Host $download_host;
# Do not touch local disks when proxying content to clients
proxy_max_temp_file_size 0;
# Stream the file back send to the browser
proxy_pass $download_url?$args;
}
这适用于代理GET请求,例如:
proxy_image('http://10.10.0.7:80/download?path=/20140407_120500_to_120559.mp4')
但是,我想代理一个请求,该请求传递一个不适合GET请求的文件列表.所以我需要传递$args中当前的内容作为POST数据.
我如何代理这个POST数据? – 我需要做一些像response.method =:post或者其他什么的东西吗? – 我在哪里提供我正在发布的参数?
解决方法:
我很确定你不能用nginx开箱即用.此功能实际上是为加速文件下载而设计的,因此它非常关注GET请求.
也就是说,你可以用lua模块做一些奇特的事情.在编译了包含模块的nginx版本之后,这样的东西可能会起作用.
Ruby代码:
def proxy_video(path)
self.status = 200
response.headers["X-Accel-Redirect"] = "/proxy/#{path}"
response.headers["X-Accel-Post-Body"] = "var1=val1&var2=val2"
render text: 'ok'
end
Nginx配置:
location ~* ^/proxy/(.*?)/(.*) {
internal;
resolver 127.0.0.1;
# Compose download url
set $download_host $1;
set $download_url http://$download_host/$2;
rewrite_by_lua '
ngx.req.set_method(ngx.HTTP_POST)
ngx.req.set_body_data(ngx.header["X-Accel-Post-Body"])
';
# Set download request headers
proxy_set_header Host $download_host;
# Do not touch local disks when proxying content to clients
proxy_max_temp_file_size 0;
# Stream the file back send to the browser
proxy_pass $download_url?$args;
}
内容总结
以上是互联网集市为您收集整理的ruby-on-rails – 使用带有Rails的X-Accel-Redirect创建POST请求?全部内容,希望文章能够帮你解决ruby-on-rails – 使用带有Rails的X-Accel-Redirect创建POST请求?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。