Skip to content

Commit cabc991

Browse files
committed
Fix a crash on invalid request and bump v0.1.2
1 parent 4569b00 commit cabc991

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

lib/board-linuxfr.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "goliath"
2+
require "board-linuxfr/monkeypatch"
23
require "yajl"
34

45

lib/board-linuxfr/monkeypatch.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Monkeypatch Goliath to avoid it to crash on invalid parser.
2+
# It's the backport of a commit, waiting for a release. This commit:
3+
# https://github.com/postrank-labs/goliath/commit/79d43b80c9c1345034c6f40a60b1be064e493af3
4+
5+
class Goliath::Request
6+
7+
# Invoked by connection when header parsing is complete.
8+
# This method is invoked only once per request.
9+
#
10+
# @param h [Hash] Request headers
11+
# @param parser [Http::Parser] The parser used to parse the request
12+
# @return [Nil]
13+
def parse_header(h, parser)
14+
h.each do |k, v|
15+
@env[HTTP_PREFIX + k.gsub('-','_').upcase] = v
16+
end
17+
18+
%w(CONTENT_TYPE CONTENT_LENGTH).each do |name|
19+
@env[name] = @env.delete("HTTP_#{name}") if @env["HTTP_#{name}"]
20+
end
21+
22+
if @env['HTTP_HOST']
23+
name, port = @env['HTTP_HOST'].split(':')
24+
@env[SERVER_NAME] = name if name
25+
@env[SERVER_PORT] = port if port
26+
end
27+
28+
begin
29+
uri = URI(parser.request_url)
30+
31+
@env[REQUEST_METHOD] = parser.http_method
32+
@env[REQUEST_URI] = parser.request_url
33+
@env[QUERY_STRING] = uri.query
34+
@env[HTTP_VERSION] = parser.http_version.join('.')
35+
@env[SCRIPT_NAME] = uri.path
36+
@env[REQUEST_PATH] = uri.path
37+
@env[PATH_INFO] = uri.path
38+
@env[FRAGMENT] = uri.fragment
39+
40+
yield if block_given?
41+
42+
@env[ASYNC_HEADERS].call(@env, h) if @env[ASYNC_HEADERS]
43+
rescue Exception => e
44+
server_exception(e)
45+
end
46+
end
47+
48+
end

lib/board-linuxfr/redis_plugin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class BoardLinuxfr
99
class RedisPlugin
10-
def initialize(port, config, status, logger)
10+
def initialize(address, port, config, status, logger)
1111
logger.info "Initializing the Redis plugin"
1212
@logger = logger
1313
@chans = status[:channels] = Hash.new { |h,k| h[k] = EM::Channel.new }

lib/board-linuxfr/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class BoardLinuxfr
2-
VERSION = "0.1.1"
2+
VERSION = "0.1.2"
33
end

0 commit comments

Comments
 (0)