diff --git a/lib/protocol/http1/connection.rb b/lib/protocol/http1/connection.rb index 8745041..9ccffaa 100644 --- a/lib/protocol/http1/connection.rb +++ b/lib/protocol/http1/connection.rb @@ -173,7 +173,7 @@ def read_line read_line? or raise EOFError end - def read_request + def read_request_preface return unless line = read_line? if match = line.match(REQUEST_LINE) @@ -182,6 +182,13 @@ def read_request raise InvalidRequest, line.inspect end + return method, path, version + end + + def read_request + method, path, version = read_request_preface + return unless method + headers = read_headers @persistent = persistent?(version, method, headers) @@ -193,11 +200,17 @@ def read_request return headers.delete(HOST), method, path, version, headers, body end - def read_response(method) + def read_response_preface version, status, reason = read_line.split(/\s+/, 3) status = Integer(status) + return version, status, reason + end + + def read_response(method) + version, status, reason = read_response_preface + headers = read_headers @persistent = persistent?(version, method, headers)