Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breakout reading of request and response prefaces #23

Merged
merged 2 commits into from
Dec 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/protocol/http1/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def read_line
read_line? or raise EOFError
end

def read_request
def read_request_line
return unless line = read_line?

if match = line.match(REQUEST_LINE)
Expand All @@ -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_line
return unless method

headers = read_headers

@persistent = persistent?(version, method, headers)
Expand All @@ -193,11 +200,17 @@ def read_request
return headers.delete(HOST), method, path, version, headers, body
end

def read_response(method)
def read_status_line
version, status, reason = read_line.split(/\s+/, 3)

status = Integer(status)

return version, status, reason
end

def read_response(method)
version, status, reason = read_status_line

headers = read_headers

@persistent = persistent?(version, method, headers)
Expand Down