2010-10-25 20 views

cevap

47

Ben -D ve -V bayraklarıyla ince çalıştırın:

$ thin start -p 3000 -R config.ru -D -V 

-D, --debug      Set debbuging on 
-V, --trace      Set tracing on (log raw request/response) 

Eğer bir istek ham çıktı almak gibi istek yöntemini kullanmaya çalışıyorsanız:

# 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 

Daha fazla bilgi için bkz. "GETTING STARTED".

+0

ben bir günlük dosyasına olduğu gibi her HTTP isteğini dump 'em-proxy' kullanarak bir vekil oluşturdu. – t6d

+0

cool, harika bir seçenek sunuyor. kodunuzu gönderir misiniz Bunu öğrenmek istiyorum: D – include

+0

'config.ru' nerede? – evandrix

17

Belki de bu sizin sorduğunuz şey değil, ancak buraya, Sinatra'daki tüm HTTP istek başlıklarını görmenin bir yolunu aramaya geldim (aslında onları sorgulamak zorunda kalmadan, bir proxy isteğini ayıklamak zorunda kalmadan). Oldukça kullanışlı buldum:

get "/my_route" do 
    puts "#{ request.env }" 
end 

Veya, bir okunaklı json formatında cevaben o damla döndürmek için: işte

require 'json' 
get "/my_route" do 
    content_type :text 
    return JSON.pretty_generate(request.env) 
end 

Ve tüm istek ayrıntıları:

{ 
    "SERVER_SOFTWARE": "thin 1.6.2 codename Doc Brown", 
    "SERVER_NAME": "10.0.1.3", 
    "rack.input": "#<StringIO:0x00000002bf82c0>", 
    "rack.version": [ 
    1, 
    0 
    ], 
    "rack.errors": "#<IO:0x00000002549b90>", 
    "rack.multithread": false, 
    "rack.multiprocess": false, 
    "rack.run_once": false, 
    "REQUEST_METHOD": "GET", 
    "REQUEST_PATH": "/my_route", 
    "PATH_INFO": "/my_route", 
    "REQUEST_URI": "/my_route", 
    "HTTP_VERSION": "HTTP/1.0", 
    "HTTP_X_FORWARDED_FOR": "10.0.1.3, 127.0.0.1, 127.0.0.1, 127.0.0.1", 
    "HTTP_HOST": "10.0.1.3:9393", 
    "HTTP_CONNECTION": "close", 
    "HTTP_X_REAL_IP": "10.0.1.3", 
    "HTTP_X_FE_SCHEME": "http", 
    "HTTP_X_FE_HOST": "10.0.10.145", 
    "HTTP_X_FE_ROUTE": "/my_route", 
    "HTTP_ACCEPT": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", 
    "HTTP_USER_AGENT": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36", 
    "HTTP_ACCEPT_LANGUAGE": "en-US,en;q=0.8", 
    "HTTP_X_VARNISH": "917254702", 
    "HTTP_ACCEPT_ENCODING": "gzip", 
    "GATEWAY_INTERFACE": "CGI/1.2", 
    "SERVER_PORT": "9393", 
    "QUERY_STRING": "", 
    "SERVER_PROTOCOL": "HTTP/1.1", 
    "rack.url_scheme": "http", 
    "SCRIPT_NAME": "", 
    "REMOTE_ADDR": "10.0.10.145", 
    "async.callback": "#<Method: Thin::Connection#post_process>", 
    "async.close": "#<EventMachine::DefaultDeferrable:0x00000002a60070>", 
    "rack.logger": "#<Rack::NullLogger:0x00000004154ad8>", 
    "rack.request.query_string": "", 
    "rack.request.query_hash": { 
    }, 
    "sinatra.route": "GET (?-mix:^\\/my_route$)" 
}