3

WEBrick で PUT リクエストを処理するにはどうすればよいですか?

AbstractServlet クラスで do_PUT() メソッドを定義しようとしましたが、メソッドが呼び出されません。

4

1 に答える 1

1

私は同じ問題を抱えており、独自のカスタム WEBrick::HTTPProxyServer を作成し、そこに put メソッドを追加することで機能しました。

require "webrick"
require "webrick/httpproxy"
require 'cgi'

class CustomWEBrickProxyServer < WEBrick::HTTPProxyServer

  def do_PUT(req, res)
    perform_proxy_request(req, res) do |http, path, header|
      http.put(path, req.body || "", header)
    end
  end

  # This method is not needed for PUT but I added for completeness
  def do_OPTIONS(req, res)
    res['allow'] = "GET,HEAD,POST,OPTIONS,CONNECT,PUT"
  end

end

次に、独自のカスタム クラスを使用してプロキシ サーバーを起動する必要があります。

my_proxy_server = CustomWEBrickProxyServer.new :Port=> proxy_port,
                                               :ProxyVia => forward_proxy,
                                               :ProxyURI => forward_proxy,
                                               :RequestCallback => method(:request_callback),
                                               :ProxyContentHandler => method(:response_callback),
                                               :AccessLog => method(:access_log)
于 2013-09-25T18:03:37.480 に答える