From ddd90b5438f885df7d024df82012dbfa31a5e0c5 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Thu, 17 Apr 2014 02:19:14 +0100 Subject: [PATCH] Tweak the regexes for parsing HTTP. --- lib/websocket/http/headers.rb | 2 +- lib/websocket/http/request.rb | 2 +- lib/websocket/http/response.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/websocket/http/headers.rb b/lib/websocket/http/headers.rb index 8322345..f106518 100644 --- a/lib/websocket/http/headers.rb +++ b/lib/websocket/http/headers.rb @@ -6,7 +6,7 @@ module WebSocket CR = 0x0D LF = 0x0A - HEADER_LINE = /^([!#\$%&'\*\+\-\.\^_`\|~0-9a-z]+):\s*((?:\t|[\x20-\x7e])*?)\s*$/i + HEADER_LINE = /^([!#\$%&'\*\+\-\.\\\^_`\|~0-9a-z]+):\s*([\x20-\x7e]*?)\s*$/i attr_reader :headers diff --git a/lib/websocket/http/request.rb b/lib/websocket/http/request.rb index 9406d4d..bd66bac 100644 --- a/lib/websocket/http/request.rb +++ b/lib/websocket/http/request.rb @@ -4,7 +4,7 @@ module WebSocket class Request include Headers - REQUEST_LINE = /^([A-Z]+) +([\x21-\x7e]+) +(HTTP\/[0-9]\.[0-9])$/ + 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] diff --git a/lib/websocket/http/response.rb b/lib/websocket/http/response.rb index 1a7d891..236d259 100644 --- a/lib/websocket/http/response.rb +++ b/lib/websocket/http/response.rb @@ -4,7 +4,7 @@ module WebSocket class Response include Headers - STATUS_LINE = /^(HTTP\/[0-9]\.[0-9]) +([0-9]{3}) +(.*)$/ + STATUS_LINE = /^(HTTP\/[0-9]+\.[0-9]+) ([0-9]{3}) ([\x20-\x7e]+)$/ attr_reader :code