如何完全阻止 rails 操作响应任何类型的 HTTP 状态?
How to completely stop the rails action from responding any kind of HTTP status?
RAILS 3.2.13。 JRUBY 1.7.15。 RUBY 1.9.3 作为解释器
有没有办法完全阻止 Rails 操作的响应?我想这样做是为了避免将任何类型的响应发送回匿名黑客。在索引之前有一个约束检查,如果约束检查失败,理想情况下索引方法应该停止响应。这是 REST API 的一小部分,目的是阻止发送回任何 http 状态的操作。
欢迎提出建设性的建议。
即
def index
# kill method, do not send any response at all. not even 500 error
end
谢谢大家的帮助。
尽管 REST API 可能会发送有效的 HTTP 响应,但您可以通过关闭底层输出流来抑制任何输出。这是通过 Rack 的 hijacking API 公开的(假设您的服务器支持它):
def index
if env['rack.hijack?']
env['rack.hijack'].call
io = env['rack.hijack_io']
io.close
end
end
这会导致空回复,即服务器只是关闭连接而不发送任何数据:
$ curl -v http://localhost:3000/
* Connected to localhost port 3000
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:3000
> Accept: */*
>
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server
RAILS 3.2.13。 JRUBY 1.7.15。 RUBY 1.9.3 作为解释器
有没有办法完全阻止 Rails 操作的响应?我想这样做是为了避免将任何类型的响应发送回匿名黑客。在索引之前有一个约束检查,如果约束检查失败,理想情况下索引方法应该停止响应。这是 REST API 的一小部分,目的是阻止发送回任何 http 状态的操作。
欢迎提出建设性的建议。
即
def index
# kill method, do not send any response at all. not even 500 error
end
谢谢大家的帮助。
尽管 REST API 可能会发送有效的 HTTP 响应,但您可以通过关闭底层输出流来抑制任何输出。这是通过 Rack 的 hijacking API 公开的(假设您的服务器支持它):
def index
if env['rack.hijack?']
env['rack.hijack'].call
io = env['rack.hijack_io']
io.close
end
end
这会导致空回复,即服务器只是关闭连接而不发送任何数据:
$ curl -v http://localhost:3000/
* Connected to localhost port 3000
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:3000
> Accept: */*
>
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server