Sha256: 21b5a3e00650d667636eee2fc9833d1645a6076b947153c70692a652bfe692a1

Contents?: true

Size: 1.12 KB

Versions: 107

Compression:

Stored size: 1.12 KB

Contents

module WebSocket
  module HTTP

    class Request
      include Headers

      REQUEST_LINE     = /^(OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT) ([\x21-\x7e]+) (HTTP\/[0-9]+\.[0-9]+)$/
      REQUEST_TARGET   = /^(.*?)(\?(.*))?$/
      RESERVED_HEADERS = %w[content-length content-type]

      attr_reader :env

    private

      def start_line(line)
        return false unless parsed = line.scan(REQUEST_LINE).first

        target = parsed[1].scan(REQUEST_TARGET).first

        @env = {
          'REQUEST_METHOD' => parsed[0],
          'SCRIPT_NAME'    => '',
          'PATH_INFO'      => target[0],
          'QUERY_STRING'   => target[2] || ''
        }
        true
      end

      def complete
        super
        @headers.each do |name, value|
          rack_name = name.upcase.gsub(/-/, '_')
          rack_name = "HTTP_#{rack_name}" unless RESERVED_HEADERS.include?(name)
          @env[rack_name] = value
        end
        if host = @env['HTTP_HOST']
          uri = URI.parse("http://#{host}")
          @env['SERVER_NAME'] = uri.host
          @env['SERVER_PORT'] = uri.port.to_s
        end
      end
    end

  end
end

Version data entries

107 entries across 79 versions & 11 rubygems

Version Path
websocket-driver-0.5.0-java lib/websocket/http/request.rb
websocket-driver-0.4.0-java lib/websocket/http/request.rb
websocket-driver-0.4.0 lib/websocket/http/request.rb
websocket-driver-0.3.5 lib/websocket/http/request.rb
websocket-driver-0.3.5-java lib/websocket/http/request.rb
websocket-driver-0.3.4-java lib/websocket/http/request.rb
websocket-driver-0.3.4 lib/websocket/http/request.rb