Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Net::HTTPSession#response_body_encoding=

response_body_encoding=(value)

Sets the encoding to be used for the response body; returns the encoding.

The given value may be:

  • An Encoding object.

  • The name of an encoding.

  • An alias for an encoding name.

See Encoding.

Examples:

Example
http = Net::HTTP.new(hostname)
http.response_body_encoding = Encoding::US_ASCII # => #<Encoding:US-ASCII>
http.response_body_encoding = 'US-ASCII'         # => "US-ASCII"
http.response_body_encoding = 'ASCII'            # => "ASCII"