Skip to content

Commit

Permalink
breakout reading of request and response prefaces
Browse files Browse the repository at this point in the history
  • Loading branch information
zarqman authored and ioquatix committed Dec 26, 2023
1 parent 26ffd54 commit 3089318
Showing 1 changed file with 15 additions and 2 deletions.
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_preface
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_preface
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_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)
Expand Down

0 comments on commit 3089318

Please sign in to comment.