简体   繁体   中英

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. In fact this is a .Net application that will process print requests but it does not support SSL. The redirected request tries to connect with SSL resulting with the following in the Rails app logs...

OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3/TLS write client hello: wrong version number):

The other application simply doesn't support SSL so its nothing to do with verifying SSL certificates or SSL version numbers.

Currently I'm using the following function, which works a treat when the app is not running in under 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.

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. So my application makes a JS request to my rails application and my rails routes directs the request to a controller function as follows: -

 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. No need Rack:Proxy anymore either.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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