Calling Sinatra from Sinatra produces results different from external request

∥☆過路亽.° 提交于 2019-12-11 08:27:33

问题


Following my question here. So I am trying to do a smart redirect using this:

get "/category/:id/merge" do
    #... setting @catalog_id and category
    call env.merge("PATH_INFO" => "/catalog/#{@catalog_id}/category/#{category.id}", "REQUEST_METHOD"=>"PATCH","QUERY_STRING"=>"merge=1")
    status 200
end

But when I look in logs, I see something that is not only frustrating but also completely absurd:

# this one is from internal call
I, [2013-03-21T15:55:54.382153 #29569]  INFO -- : Processing GET /catalog/1/category/2686/merge
I, [2013-03-21T15:55:54.382239 #29569]  INFO -- : Parameters: {}
...
I, [2013-03-21T15:55:54.394992 #29569]  INFO -- : Processing PATCH /catalog/1/category/2686
I, [2013-03-21T15:55:54.395041 #29569]  INFO -- : Parameters: {"merge"=>"1"}
I, [2013-03-21T15:55:54.395560 #29569]  INFO -- : Processed PATCH /catalog/1/category/2686?merge=1 with status code 404
I, [2013-03-21T15:55:54.395669 #29569]  INFO -- : Processed GET /catalog/1/category/2686/merge with status code 200

# this one is a direct request
I, [2013-03-21T15:56:36.246535 #29588]  INFO -- : Processing PATCH /catalog/1/category/2686
I, [2013-03-21T15:56:36.246629 #29588]  INFO -- : Parameters: {"merge"=>"1"}
...
I, [2013-03-21T15:56:36.286216 #29588]  INFO -- : Processed PATCH /catalog/1/category/2686?merge=1 with status code 204

And the body of internal 404 request is just Sinatra's standard 404 error page. How the hell can he tell me straight in the eye that he doesn't know this route if I caught him serving exactly the same URL with acceptable 204?

UPDATE It gets even more exciting when I change REQUEST_METHOD to GET - works like a charm.

I, [2013-03-21T17:09:37.718756 #3141]  INFO -- : Processing GET /catalog/1/category/2686/merge
I, [2013-03-21T17:09:37.718838 #3141]  INFO -- : Parameters: {}
...
I, [2013-03-21T17:09:37.735632 #3141]  INFO -- : Processing GET /catalog/1/category/2686
I, [2013-03-21T17:09:37.735678 #3141]  INFO -- : Parameters: {"merge"=>"1"}
...
I, [2013-03-21T17:09:37.773033 #3141]  INFO -- : Processed GET /catalog/1/category/2686?merge=1 with status code 200
I, [2013-03-21T17:09:37.773143 #3141]  INFO -- : Processed GET /catalog/1/category/2686/merge with status code 200

来源:https://stackoverflow.com/questions/15547001/calling-sinatra-from-sinatra-produces-results-different-from-external-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!