简体   繁体   English

如何在启用了SSL的Rails应用程序中的单个Rack :: Proxy请求中禁用SSL?

[英]How to disable SSL in a single Rack::Proxy request within an SSL enabled Rails application?

I have an SSL enabled application and I'm redirecting a specific request to an older application, in order to avoid CORS issues. 我有一个启用SSL的应用程序,并且正在将特定请求重定向到较旧的应用程序,以避免CORS问题。 In fact this is a .Net application that will process print requests but it does not support SSL. 实际上,这是一个.Net应用程序,将处理打印请求,但不支持SSL。 The redirected request tries to connect with SSL resulting with the following in the Rails app logs... 重定向的请求尝试与SSL连接,从而在Rails应用程序日志中生成以下内容...

OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3/TLS write client hello: wrong version number): OpenSSL :: SSL :: SSLError(返回的SSL_connect = 1 errno = 0 state = SSLv3 / TLS向客户端问好:版本号错误):

The other application simply doesn't support SSL so its nothing to do with verifying SSL certificates or SSL version numbers. 另一个应用程序根本不支持SSL,因此与验证SSL证书或SSL版本号无关。

Currently I'm using the following function, which works a treat when the app is not running in under SSL 目前,我正在使用以下功能,当应用程序未在SSL下运行时,该功能可以解决问题

def perform_request(env)

 request = Rack::Request.new(env)

 if request.path.include? "proxy_process_dispatch"

   env["http.read_timeout"] = (OFFICE_PRINT_TIMEOUT / 1000) - 1

   env["HTTP_HOST"] = OFFICE_IP + ':' + OFFICE_PRINT_SERVER_PORT     

   env["REQUEST_PATH"] = "/?process=true"

  super(env)

 else

   @app.call(env)

 end

end

It seems that because the original request was SSL the redirected request is also SSL but I need to ensure that its a standard HTTP request, though on a non-standard port. 似乎因为原始请求是SSL,所以重定向的请求也是SSL,但我需要确保它是标准HTTP请求,尽管是在非标准端口上。

OK, so I decided that I was going about this the wrong way and rather than using Rack::Proxy to divert requests to avoid CORS issues I simply used the Net:HTTP functions to make a new, simple, request. 好的,所以我决定我将以这种错误的方式进行操作,而不是使用Rack :: Proxy转移请求以避免发生CORS问题,我只是使用Net:HTTP函数创建了一个新的简单请求。 So my application makes a JS request to my rails application and my rails routes directs the request to a controller function as follows: - 因此,我的应用程序向我的rails应用程序发出了JS请求,并且我的rails路由将请求定向到控制器功能,如下所示:-

 require "net/http"
 require "uri"

 def process_dispatch_list
    uri = URI.parse("http://#{OFFICE_IP}")
    http = Net::HTTP.new(OFFICE_IP, OFFICE_PRINT_SERVER_PORT)
    http.use_ssl = false
    http.read_timeout = (OFFICE_PRINT_TIMEOUT / 1000) - 1
    request = Net::HTTP::Get.new(uri.request_uri + "?process_dispatch=true")
    response = http.request(request)
    case response
      when Net::HTTPSuccess
        render json: response.body, status: :ok
      else
        render json: response.body, status: :unprocessable_entity
    end  
  end

Works a treat, my response is interpreted in the front end ajax request and reports success of failure using pnotify based on the response status. 工作正常,我的响应在前端ajax请求中进行解释,并根据响应状态使用pnotify报告失败的成功。 No need Rack:Proxy anymore either. 不再需要Rack:Proxy了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM