Module: Seahorse::Client::NetHttp::Patches::RequestPatches Private

Defined in:
lib/seahorse/client/net_http/patches.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Patches intended to override Net::HTTP functionality

Defined Under Namespace

Classes: RequestIO

Instance Method Summary collapse

Instance Method Details

#send_request_with_body_stream(sock, ver, path, f) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

IO.copy_stream is capped at 16KB buffer so this patch intends to increase its chunk size for better performance. Only intended to use for S3 TM implementation. See: github.com/ruby/net-http/blob/master/lib/net/http/generic_request.rb#L292



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/seahorse/client/net_http/patches.rb', line 34

def send_request_with_body_stream(sock, ver, path, f)
  return super unless (chunk_size = Thread.current[:net_http_override_body_stream_chunk])

  unless content_length || chunked?
    raise ArgumentError, 'Content-Length not given and Transfer-Encoding is not `chunked`'
  end

  supply_default_content_type
  write_header(sock, ver, path)
  wait_for_continue sock, ver if sock.continue_timeout
  if chunked?
    chunker = Chunker.new(sock)
    RequestIO.custom_stream(f, chunker, chunk_size)
    chunker.finish
  else
    RequestIO.custom_stream(f, sock, chunk_size)
  end
end

#supply_default_content_typeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

For requests with bodies, Net::HTTP sets a default content type of:

'application/x-www-form-urlencoded'

There are cases where we should not send content type at all. Even when no body is supplied, Net::HTTP uses a default empty body and sets it anyway. This patch disables the behavior when a Thread local variable is set. See: github.com/ruby/net-http/issues/205



24
25
26
27
28
# File 'lib/seahorse/client/net_http/patches.rb', line 24

def supply_default_content_type
  return if Thread.current[:net_http_skip_default_content_type]

  super
end