class ActionDispatch::Response

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/action_dispatch/http/response.rbs

class ActionDispatch::Response
  def self.create: (?Integer status, ?Hash header, ?Array[] body, default_headers: Hash) -> ActionDispatch::Response
  def assign_default_content_type_and_charset!: () -> nil
  def body=: (Array[String] body) -> ActionDispatch::Response::Buffer
  def build_buffer: (ActionDispatch::Response response, Array[] body) -> ActionDispatch::Response::Buffer
  def commit!: () -> Thread::ConditionVariable
  def committed?: () -> false
  def content_type=: (String content_type) -> String
  def get_header: (String key) -> String?
  def handle_no_content!: () -> nil
  def initialize: (?Integer status, ?Hash header, ?Array[] body) -> void
  def media_type: () -> String?
  def munge_body_object: ((Array[] | Array[String]) body) -> untyped
  def parse_content_type: (String? content_type) -> ActionDispatch::Response::ContentTypeHeader
  def parsed_content_type_header: () -> ActionDispatch::Response::ContentTypeHeader
  def rack_response: (Integer status, Hash header) -> Array[Integer]
  def reset_body!: () -> ActionDispatch::Response::Buffer
  def sending?: () -> false
  def sent?: () -> false
  def set_content_type: (String content_type, Encoding charset) -> String
  def set_header: (String key, String v) -> String
  def status=: (Integer status) -> Integer
  def to_a: () -> Array[Integer]
end

end
end
puts response.body
get(‘/’)
def test_print_root_path_to_console
class DemoControllerTest < ActionDispatch::IntegrationTest
controller response to the console:
For example, the following demo integration test prints the body of the
objects of type TestResponse (which are of course also of type Response).
Integration::RequestHelpers#get and Integration::RequestHelpers#post return
developers. Integration test methods such as
more detail, and that’s when Response can be useful for application
Nevertheless, integration tests may want to inspect controller responses in
ActionControllerBase#headers instead of Response#headers.
to set the HTTP response’s content MIME type, then use
methods defined in ActionController::Base instead. For example, if you want
should never be used directly in controllers. Controllers should use the
Response is mostly a Ruby on Rails framework implementation detail, and
from integration tests).
back to the web browser) or a TestResponse (i.e. one that is generated
either represent a real HTTP response (i.e. one that is meant to be sent
retrieve the current state of the response, or customize the response. It can
Represents an HTTP response generated by a controller action. Use it to
:nodoc:

def self.create(status = 200, header = {}, body = [], default_headers: self.default_headers)

Experimental RBS support (using type sampling data from the type_fusion project).

def self.create: (?Integer status, ?X-Frame-Options | String | X-XSS-Protection | String | X-Content-Type-Options | String | X-Download-Options | String | X-Permitted-Cross-Domain-Policies | String | Referrer-Policy | String header, ? body, default_headers: X-Frame-Options | String | X-XSS-Protection | String | X-Content-Type-Options | String | X-Download-Options | String | X-Permitted-Cross-Domain-Policies | String | Referrer-Policy | String) -> ActionDispatch::Response

This signature was generated using 1 sample from 1 application.

def self.create(status = 200, header = {}, body = [], default_headers: self.default_headers)
  header = merge_default_headers(header, default_headers)
  new status, header, body
end

def self.merge_default_headers(original, default)

def self.merge_default_headers(original, default)
  default.respond_to?(:merge) ? default.merge(original) : original
end

def abort

def abort
  if stream.respond_to?(:abort)
    stream.abort
  elsif stream.respond_to?(:close)
    # `stream.close` should really be reserved for a close from the
    # other direction, but we must fall back to it for
    # compatibility.
    stream.close
  end
end

def assign_default_content_type_and_charset!

Experimental RBS support (using type sampling data from the type_fusion project).

def assign_default_content_type_and_charset!: () -> nil

This signature was generated using 1 sample from 1 application.

def assign_default_content_type_and_charset!
  return if media_type
  ct = parsed_content_type_header
  set_content_type(ct.mime_type || Mime[:html].to_s,
                   ct.charset || self.class.default_charset)
end

def await_commit

def await_commit
  synchronize do
    @cv.wait_until { @committed }
  end
end

def await_sent

def await_sent
  synchronize { @cv.wait_until { @sent } }
end

def before_committed

def before_committed
  return if committed?
  assign_default_content_type_and_charset!
  merge_and_normalize_cache_control!(@cache_control)
  handle_conditional_get!
  handle_no_content!
end

def before_sending

def before_sending
  # Normally we've already committed by now, but it's possible
  # (e.g., if the controller action tries to read back its own
  # response) to get here before that. In that case, we must force
  # an "early" commit: we're about to freeze the headers, so this is
  # our last chance.
  commit! unless committed?
  headers.freeze
  request.commit_cookie_jar! unless committed?
end

def body

of any calls to render.
Returns the content of the response as a string. This contains the contents
def body
  @stream.body
end

def body=(body)

Experimental RBS support (using type sampling data from the type_fusion project).

def body=: ( body) -> ActionDispatch::Response::Buffer

This signature was generated using 1 sample from 1 application.

Allows you to manually set or override the response body.
def body=(body)
  if body.respond_to?(:to_path)
    @stream = body
  else
    synchronize do
      @stream = build_buffer self, munge_body_object(body)
    end
  end
end

def body_parts

def body_parts
  parts = []
  @stream.each { |x| parts << x }
  parts
end

def build_buffer(response, body)

Experimental RBS support (using type sampling data from the type_fusion project).

def build_buffer: (ActionDispatch::Response response,  body) -> ActionDispatch::Response::Buffer

This signature was generated using 1 sample from 1 application.

def build_buffer(response, body)
  Buffer.new response, body
end

def charset

content you're giving them, so we need to send that along.
The charset of the response. HTML wants to know the encoding of the
def charset
  header_info = parsed_content_type_header
  header_info.charset || self.class.default_charset
end

def charset=(charset)

response.charset = nil # => 'utf-8'
response.charset = 'utf-16' # => 'utf-16'

it sets the charset to +default_charset+.
Sets the HTTP character set. In case of +nil+ parameter
def charset=(charset)
  content_type = parsed_content_type_header.mime_type
  if false == charset
    set_content_type content_type, nil
  else
    set_content_type content_type, charset || self.class.default_charset
  end
end

def close

def close
  stream.close if stream.respond_to?(:close)
end

def code

Returns a string to ensure compatibility with Net::HTTPResponse.
def code
  @status.to_s
end

def commit!

Experimental RBS support (using type sampling data from the type_fusion project).

def commit!: () -> Thread::ConditionVariable

This signature was generated using 1 sample from 1 application.

def commit!
  synchronize do
    before_committed
    @committed = true
    @cv.broadcast
  end
end

def committed?; synchronize { @committed }; end

Experimental RBS support (using type sampling data from the type_fusion project).

def committed?: () -> false

This signature was generated using 10 samples from 1 application.

def committed?; synchronize { @committed }; end

def content_type

Content type of response.
def content_type
  super.presence
end

def content_type=(content_type)

Experimental RBS support (using type sampling data from the type_fusion project).

def content_type=: (String content_type) -> String

This signature was generated using 2 samples from 1 application.

information.
the character set information will also be included in the content type
If a character set has been defined for this response (see charset=) then

response.content_type = "text/plain"

you could write this:
Sets the HTTP response's content MIME type. For example, in the controller
def content_type=(content_type)
  return unless content_type
  new_header_info = parse_content_type(content_type.to_s)
  prev_header_info = parsed_content_type_header
  charset = new_header_info.charset || prev_header_info.charset
  charset ||= self.class.default_charset unless prev_header_info.mime_type
  set_content_type new_header_info.mime_type, charset
end

def cookies

assert_equal 'AuthorOfNewPage', r.cookies['author']

Returns the response cookies, converted to a Hash of (name => value) pairs
def cookies
  cookies = {}
  if header = get_header(SET_COOKIE)
    header = header.split("\n") if header.respond_to?(:to_str)
    header.each do |cookie|
      if pair = cookie.split(";").first
        key, value = pair.split("=").map { |v| Rack::Utils.unescape(v) }
        cookies[key] = value
      end
    end
  end
  cookies
end

def delete_header(key); headers.delete key; end

def delete_header(key); headers.delete key; end

def each(&block)

def each(&block)
  sending!
  x = @stream.each(&block)
  sent!
  x
end

def get_header(key); headers[key]; end

Experimental RBS support (using type sampling data from the type_fusion project).

def get_header: (String key) -> String?

This signature was generated using 9 samples from 2 applications.

def get_header(key);    headers[key];       end

def handle_no_content!

Experimental RBS support (using type sampling data from the type_fusion project).

def handle_no_content!: () -> nil

This signature was generated using 1 sample from 1 application.

def handle_no_content!
  if NO_CONTENT_CODES.include?(@status)
    @header.delete CONTENT_TYPE
    @header.delete "Content-Length"
  end
end

def has_header?(key); headers.key? key; end

def has_header?(key);   headers.key? key;   end

def initialize(status = 200, header = {}, body = [])

Experimental RBS support (using type sampling data from the type_fusion project).

def initialize: (?Integer status, ?X-Frame-Options | String | X-XSS-Protection | String | X-Content-Type-Options | String | X-Download-Options | String | X-Permitted-Cross-Domain-Policies | String | Referrer-Policy | String header, ? body) -> void

This signature was generated using 5 samples from 1 application.

def initialize(status = 200, header = {}, body = [])
  super()
  @header = Header.new(self, header)
  self.body, self.status = body, status
  @cv           = new_cond
  @committed    = false
  @sending      = false
  @sent         = false
  prepare_cache_control!
  yield self if block_given?
end

def media_type

Experimental RBS support (using type sampling data from the type_fusion project).

def media_type: () -> String?

This signature was generated using 2 samples from 1 application.

Media type of response.
def media_type
  parsed_content_type_header.mime_type
end

def message


response.message # => "Not Found"
response.status = 404

response.message # => "OK"
response.status = 200

Returns the corresponding message for the current HTTP status code:
def message
  Rack::Utils::HTTP_STATUS_CODES[@status]
end

def munge_body_object(body)

Experimental RBS support (using type sampling data from the type_fusion project).

def munge_body_object: ( body) -> untyped

This signature was generated using 2 samples from 1 application.

def munge_body_object(body)
  body.respond_to?(:each) ? body : [body]
end

def parse_content_type(content_type)

Experimental RBS support (using type sampling data from the type_fusion project).

def parse_content_type: (String? content_type) -> ActionDispatch::Response::ContentTypeHeader

This signature was generated using 9 samples from 1 application.

def parse_content_type(content_type)
  if content_type && match = CONTENT_TYPE_PARSER.match(content_type)
    ContentTypeHeader.new(match[:mime_type], match[:charset])
  else
    NullContentTypeHeader
  end
end

def parsed_content_type_header

Experimental RBS support (using type sampling data from the type_fusion project).

def parsed_content_type_header: () -> ActionDispatch::Response::ContentTypeHeader

This signature was generated using 4 samples from 1 application.

content type header.
Small internal convenience method to get the parsed version of the current
def parsed_content_type_header
  parse_content_type(get_header(CONTENT_TYPE))
end

def rack_response(status, header)

Experimental RBS support (using type sampling data from the type_fusion project).

def rack_response: (Integer status, (X-Frame-Options | String | X-XSS-Protection | String | X-Content-Type-Options | String | X-Download-Options | String | X-Permitted-Cross-Domain-Policies | String | Referrer-Policy | String | Link | String | Content-Type | String | Vary | String | X-Frame-Options | String | X-XSS-Protection | String | X-Content-Type-Options | String | X-Download-Options | String | X-Permitted-Cross-Domain-Policies | String | Referrer-Policy | String | Link | String | Content-Type | String) header) -> Hash | X-Frame-Options | String | X-XSS-Protection | String | X-Content-Type-Options | String | X-Download-Options | String | X-Permitted-Cross-Domain-Policies | String | Referrer-Policy | String | Link | String | Content-Type | String | ActionDispatch::Response::RackBody

This signature was generated using 2 samples from 2 applications.

def rack_response(status, header)
  if NO_CONTENT_CODES.include?(status)
    [status, header, []]
  else
    [status, header, RackBody.new(self)]
  end
end

def reset_body!

Experimental RBS support (using type sampling data from the type_fusion project).

def reset_body!: () -> ActionDispatch::Response::Buffer

This signature was generated using 1 sample from 1 application.

def reset_body!
  @stream = build_buffer(self, [])
end

def response_code

The response code of the request.
def response_code
  @status
end

def send_file(path)

Send the file stored at +path+ as the response body.
def send_file(path)
  commit!
  @stream = FileBody.new(path)
end

def sending!

def sending!
  synchronize do
    before_sending
    @sending = true
    @cv.broadcast
  end
end

def sending?; synchronize { @sending }; end

Experimental RBS support (using type sampling data from the type_fusion project).

def sending?: () -> false

This signature was generated using 2 samples from 1 application.

def sending?;   synchronize { @sending };   end

def sending_file=(v)

def sending_file=(v)
  if true == v
    self.charset = false
  end
end

def sent!

def sent!
  synchronize do
    @sent = true
    @cv.broadcast
  end
end

def sent?; synchronize { @sent }; end

Experimental RBS support (using type sampling data from the type_fusion project).

def sent?: () -> false

This signature was generated using 1 sample from 1 application.

def sent?;      synchronize { @sent };      end

def set_content_type(content_type, charset)

Experimental RBS support (using type sampling data from the type_fusion project).

def set_content_type: (String content_type, Encoding charset) -> String

This signature was generated using 1 sample from 1 application.

def set_content_type(content_type, charset)
  type = content_type || ""
  type = "#{type}; charset=#{charset.to_s.downcase}" if charset
  set_header CONTENT_TYPE, type
end

def set_header(key, v); headers[key] = v; end

Experimental RBS support (using type sampling data from the type_fusion project).

def set_header: (String key, String v) -> String

This signature was generated using 2 samples from 1 application.

def set_header(key, v); headers[key] = v;   end

def status=(status)

Experimental RBS support (using type sampling data from the type_fusion project).

def status=: (Integer status) -> Integer

This signature was generated using 2 samples from 1 application.

Sets the HTTP status code.
def status=(status)
  @status = Rack::Utils.status_code(status)
end

def to_a

Experimental RBS support (using type sampling data from the type_fusion project).

def to_a: () -> Hash | X-Frame-Options | String | X-XSS-Protection | String | X-Content-Type-Options | String | X-Download-Options | String | X-Permitted-Cross-Domain-Policies | String | Referrer-Policy | String | Link | String | Content-Type | String | ActionDispatch::Response::RackBody

This signature was generated using 2 samples from 1 application.

status, headers, body = *response

and body. Allows explicit splatting:
Turns the Response into a Rack-compatible array of the status, headers,
def to_a
  commit!
  rack_response @status, @header.to_hash
end

def write(string)

def write(string)
  @stream.write string
end