Thin with SSL support and ruby-debug

后端 未结 4 462
梦如初夏
梦如初夏 2020-12-17 00:04

Does anyone know of a way to run the ruby debugger and SSL at the same time with Thin?

I\'ve been using Thin successfully with Rails 3.0.10.

I start it using

4条回答
  •  感动是毒
    2020-12-17 00:51

    I was able to successfully get the debugging working with ssl enabled thin, using the solution suggested by nathan. Though I had to do one small change of deferring initialization of @ssl after the call of initialize_without_ssl (an alias method for the original TcpServer's initialize)

    require 'thin'
    module Thin
      module Backends
        TcpServer.class_eval do
          def initialize_with_SSL(host, port)
            if Rails.env.development?
              Rails.logger.info "Loading SSL certs from ./ssl_dev..."
              @ssl_options = {
                :private_key_file => File.expand_path("../../ssl_dev/server.key", __FILE__),
                :cert_chain_file  => File.expand_path("../../ssl_dev/server.crt", __FILE__),
                :verify_peer => nil
              }
            end
    
            initialize_without_SSL(host, port)
            # @ssl initialized after calling the original initialize of TcpServer
            @ssl = true if Rails.env.development? 
    
          end
    
          alias_method :initialize_without_SSL, :initialize
          alias_method :initialize, :initialize_with_SSL      
        end
      end
    end
    
      alias_method :initialize_without_SSL, :initialize
      alias_method :initialize, :initialize_with_SSL      
    end
    

    In the above code snippett, @ssl is set to true after calling the original initialize call of Thin::Backend::TcpServer. I had to do this since the TcpServer invokes its parent's initialize (Thin::Backend:Base) that sets the @ssl to nil

      #Base initialize method. Thin gem version 1.5.0
      def initialize
        @connections                    = []
        @timeout                        = Server::DEFAULT_TIMEOUT
        @persistent_connection_count    = 0
        @maximum_connections            = Server::DEFAULT_MAXIMUM_CONNECTIONS
        @maximum_persistent_connections = Server::DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS
        @no_epoll                       = false
        @ssl                            = nil
        @threaded                       = nil
      end
    

    As noted in nathan's code block, the whole solution appears to be a hack around. In my opinion, I am fine with the snippet considering the code is done within the context of env.development and most importantly it allows debugging with ssl enabled.

提交回复
热议问题