From 30893182953251f369789a85623afef1da7ac804 Mon Sep 17 00:00:00 2001 From: thomas morgan Date: Tue, 19 Sep 2023 11:41:46 -0600 Subject: [PATCH 1/2] breakout reading of request and response prefaces --- lib/protocol/http1/connection.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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) From 490f13b4aea273c44105388c37b719aadbc233db Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Wed, 27 Dec 2023 01:14:47 +1300 Subject: [PATCH 2/2] Update connection.rb Follow the naming conventions of the RFC. --- lib/protocol/http1/connection.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protocol/http1/connection.rb b/lib/protocol/http1/connection.rb index 9ccffaa..7c6c36b 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_preface + def read_request_line return unless line = read_line? if match = line.match(REQUEST_LINE) @@ -186,7 +186,7 @@ def read_request_preface end def read_request - method, path, version = read_request_preface + method, path, version = read_request_line return unless method headers = read_headers @@ -200,7 +200,7 @@ def read_request return headers.delete(HOST), method, path, version, headers, body end - def read_response_preface + def read_status_line version, status, reason = read_line.split(/\s+/, 3) status = Integer(status) @@ -209,7 +209,7 @@ def read_response_preface end def read_response(method) - version, status, reason = read_response_preface + version, status, reason = read_status_line headers = read_headers