lib/mongrel2/testing.rb in mongrel2-0.52.2 vs lib/mongrel2/testing.rb in mongrel2-0.53.0

- old
+ new

@@ -1,6 +1,7 @@ -#!/usr/bin/env ruby +# -*- ruby -*- +# frozen_string_literal: true require 'uri' require 'pathname' require 'loggability' require 'mongrel2' @@ -106,11 +107,11 @@ DEFAULT_TESTING_HOST = DEFAULT_TESTING_URL.host DEFAULT_TESTING_PORT = DEFAULT_TESTING_URL.port DEFAULT_TESTING_ROUTE = DEFAULT_TESTING_URL.path # The default set of headers used for HTTP requests - DEFAULT_TESTING_HEADERS = { + DEFAULT_TESTING_HEADERS = Mongrel2::Table.new( 'x-forwarded-for' => '127.0.0.1', 'accept-language' => 'en-US,en;q=0.8', 'accept-encoding' => 'gzip,deflate,sdch', 'connection' => 'keep-alive', 'accept-charset' => 'UTF-8,*;q=0.5', @@ -118,11 +119,11 @@ 'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) ' + 'AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 ' + 'Safari/535.1', 'url-scheme' => 'http', 'VERSION' => 'HTTP/1.1', - } + ) # The defaults used by the HTTP request factory DEFAULT_FACTORY_CONFIG = { :sender_id => DEFAULT_TEST_UUID, :conn_id => DEFAULT_CONN_ID, @@ -159,16 +160,16 @@ def initialize( config={} ) config[:headers] = self.class.default_headers.merge( config[:headers] ) if config[:headers] config = self.class.default_factory_config.merge( config ) @sender_id = config[:sender_id] + @conn_id = config[:conn_id] @host = config[:host] @port = config[:port] @route = config[:route] - @headers = Mongrel2::Table.new( config[:headers] ) - @conn_id = 0 + @headers = Mongrel2::Table.new( config[:headers] ) end ###### public ###### @@ -284,23 +285,20 @@ end # RequestFactory # A factory for generating WebSocket request objects for testing. # - class WebSocketFrameFactory < Mongrel2::RequestFactory + class WebSocketRequestFactory < Mongrel2::RequestFactory include Mongrel2::Constants # The default host DEFAULT_TESTING_HOST = 'localhost' DEFAULT_TESTING_PORT = '8113' DEFAULT_TESTING_ROUTE = '/ws' - # The default WebSocket opcode - DEFAULT_OPCODE = :text - # Default headers - DEFAULT_TESTING_HEADERS = { + DEFAULT_TESTING_HEADERS = Mongrel2::Table.new( 'METHOD' => 'WEBSOCKET', 'PATTERN' => '/ws', 'URI' => '/ws', 'VERSION' => 'HTTP/1.1', 'PATH' => '/ws', @@ -310,11 +308,11 @@ 'sec-websocket-version' => '13', 'connection' => 'Upgrade', 'origin' => "http://#{DEFAULT_TESTING_HOST}", 'FLAGS' => '0x89', # FIN + PING 'x-forwarded-for' => '127.0.0.1' - } + ) # The defaults used by the websocket request factory DEFAULT_FACTORY_CONFIG = { :sender_id => DEFAULT_TEST_UUID, :conn_id => DEFAULT_CONN_ID, @@ -330,24 +328,10 @@ constants.each do |cname| const_get(cname).freeze end - ### Create a new factory using the specified +config+. - def initialize( config={} ) - config[:headers] = DEFAULT_TESTING_HEADERS.merge( config[:headers] ) if config[:headers] - config = DEFAULT_FACTORY_CONFIG.merge( config ) - - @sender_id = config[:sender_id] - @host = config[:host] - @port = config[:port] - @route = config[:route] - @headers = Mongrel2::Table.new( config[:headers] ) - - @conn_id = 0 - end - ###### public ###### ### Create an initial websocket handshake request and return it. @@ -445,10 +429,12 @@ headers.query = uri.query if uri.query headers.pattern = self.route headers.origin = "http://#{headers.host}" headers.flags = "0x%02x" % [ flags ] + self.log.debug "Headers are: %p" % [ headers ] + return headers end ####### @@ -486,8 +472,9 @@ end end end end # class WebSocketFrameFactory + end # module Mongrel2