如何从 Sinatra 内转储 HTTP 请求? [英] How to dump an HTTP request from within Sinatra?
本文介绍了如何从 Sinatra 内转储 HTTP 请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法以应用程序接收数据的确切方式将所有传入请求转储到 Sinatra 应用程序?也许某种 Rack 中间件?
Is there a way to dump all incoming requests to a Sinatra application in the exact way the application receives the data? Maybe some sort of Rack middleware?
推荐答案
当我想调试事物"时,我使用 -D
和 -V
标志运行瘦身:
I run thin with the -D
and -V
flags when I want to debug 'things':
$ thin start -p 3000 -R config.ru -D -V
-D, --debug Set debbuging on
-V, --trace Set tracing on (log raw request/response)
如果您尝试从请求中获取原始输出,请使用如下请求方法:
If you are trying to get the raw output from a request, use the request method like:
# app running on http://example.com/example
get '/foo' do
request.body # request body sent by the client (see below)
request.scheme # "http"
request.script_name # "/example"
request.path_info # "/foo"
request.port # 80
request.request_method # "GET"
request.query_string # ""
request.content_length # length of request.body
request.media_type # media type of request.body
request.host # "example.com"
request.get? # true (similar methods for other verbs)
request.form_data? # false
request["SOME_HEADER"] # value of SOME_HEADER header
request.referer # the referer of the client or '/'
request.user_agent # user agent (used by :agent condition)
request.cookies # hash of browser cookies
request.xhr? # is this an ajax request?
request.url # "http://example.com/example/foo"
request.path # "/example/foo"
request.ip # client IP address
request.secure? # false
request.env # raw env hash handed in by Rack
end
有关详细信息,请参阅入门".
See "GETTING STARTED" for more information.
这篇关于如何从 Sinatra 内转储 HTTP 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文