Class: Seahorse::Client::Plugins::ContentLength::Handler Private

Inherits:
Handler
  • Object
show all
Defined in:
lib/seahorse/client/plugins/content_length.rb

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

Constant Summary collapse

METHODS_WITHOUT_BODY =

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

github.com/ruby/net-http/blob/master/lib/net/http/requests.rb Methods without body are forwards compatible, because content-length may be set for requests without body but is technically incorrect.

Set.new(
  %w[GET HEAD DELETE OPTIONS TRACE COPY MOVE]
)

Instance Attribute Summary

Attributes inherited from Handler

#handler

Instance Method Summary collapse

Methods inherited from Handler

#initialize, #inspect

Constructor Details

This class inherits a constructor from Seahorse::Client::Handler

Instance Method Details

#call(context) ⇒ 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.



17
18
19
20
21
22
23
24
25
# File 'lib/seahorse/client/plugins/content_length.rb', line 17

def call(context)
  body = context.http_request.body
  method = context.http_request.http_method
  # We use Net::HTTP with body_stream which doesn't do this by default
  if body.respond_to?(:size) && !METHODS_WITHOUT_BODY.include?(method)
    context.http_request.headers['Content-Length'] = body.size
  end
  @handler.call(context)
end