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

Send headers and body in one write if possible #279

Merged
merged 1 commit into from
Dec 19, 2015
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
24 changes: 13 additions & 11 deletions lib/http/request/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def add_headers

# Stream the request to a socket
def stream
send_request_header
send_request_body
add_headers
add_body_type_headers
send_request
end

# Send headers needed to connect through proxy
Expand All @@ -64,23 +65,24 @@ def join_headers
@request_header.join(CRLF) + (CRLF) * 2
end

def send_request_header
add_headers
add_body_type_headers
def send_request
headers = join_headers

write(join_headers)
end
case @body
when NilClass
write(headers)
when String
write(headers << @body)
when Enumerable
write(headers)

def send_request_body
if @body.is_a?(String)
write(@body)
elsif @body.is_a?(Enumerable)
@body.each do |chunk|
write(chunk.bytesize.to_s(16) << CRLF)
write(chunk << CRLF)
end

write(CHUNKED_END)
else fail TypeError, "invalid body type: #{@body.class}"
end
end

Expand Down