| Use Case | Command | Description |
|---|---|---|
| Get response status | response.status | Returns the HTTP status code |
| Set content type | response.content_type = "text/html" | Set the MIME type |
| Set cookies | response.cookies["key"] = "value" | Add a cookie to the response |
| Read body | response.body | Retrieve the response body string |
| Stream response | response.stream.write("chunk") | Stream content directly |
| Redirect | response.redirect("http://example.com")? | Actually, ActionDispatch::Response likely doesn't have redirect; we can use `response.location` setting maybe? Better to omit. Use common ones. |
Represents an HTTP response generated by a controller action. Use it to retrieve the current state of the response, or customize the response. It can either represent a real HTTP response (i.e. one that is meant to be sent back to the web browser) or a TestResponse (i.e. one that is generated from integration tests).
Response is mostly a Ruby on Rails framework implementation detail, and should never be used directly in controllers. Controllers should use the methods defined in ActionController::Base instead. For example, if you want to set the HTTP response's content MIME type, then use ActionControllerBase#headers instead of Response#headers.
Nevertheless, integration tests may want to inspect controller responses in more detail, and that's when Response can be useful for application developers. Integration test methods such as ActionDispatch::Integration::Session#get and ActionDispatch::Integration::Session#post return objects of type TestResponse (which are of course also of type Response).
For example, the following demo integration test prints the body of the controller response to the console:
class DemoControllerTest < ActionDispatch::IntegrationTest
def test_print_root_path_to_console
get('/')
puts response.body
end
end
CONTENT_TYPE - [not documented]ContentTypeHeader - [not documented]LOCATION - [not documented]NO_CONTENT_CODES - [not documented]NullContentTypeHeader - [not documented]SET_COOKIE - [not documented]createmerge_default_headersnewreturn_only_media_type_on_content_typereturn_only_media_type_on_content_type=abortawait_commitawait_sentbodybody=body_partscharsetcharset=closecodecommit!committed?content_typecontent_type=cookiesdelete_headereachget_headerhas_header?headerheadersmedia_typemessageprepare!requestreset_body!response_codesend_filesending!sending?sending_file=sent!sent?set_headerstatusstatus=status_messagestreamto_awriterequest (attr_accessor)header (attr_reader)headers (attr_reader)status (attr_reader)stream (attr_reader) inside .
I'll also add a
at the end of the includes section maybe? No, it's okay.
Check rules: No , we have h2s and h3s. No emoji inside code blocks. Code block example uses < for < in class definition? I used < to escape the < in the class definition (class DemoControllerTest < ActionDispatch::IntegrationTest) to be safe. That's fine. The original had a raw < that would be a problem. So I'll use < in the code block to avoid any misinterpretation. In , it's technically okay, but better to escape. I'll do: class DemoControllerTest < ActionDispatch::IntegrationTest.
Now, the output must ONLY be the HTML, no preamble. I'll produce it.
One more thing: The first line in the input is an anchor id. Should we preserve that? Probably not needed, but we could keep it as an id on the h2 tag? The rule about preserving original HTML structure: we keep the content but we are transforming to emoji-enhanced version, so we can drop the anchor. But I think it's okay to drop. I'll just start with . I'll include the class name as text, no anchor.
Also, we should preserve the links from the original, like the link to ActionDispatch::Response itself might be in the heading? But I'll not add a link inside the heading to avoid redundancy. The original had = ActionDispatch::Response < Object. That seems like a heading that might have been auto-generated. I'll just put the text "ActionDispatch::Response" and maybe a link? Actually, the heading level can be with text; it's fine. I'll not put a link in the heading.
I'll output as a single block.📦 ActionDispatch::Response
🚀 Quick Reference
Use Case Command Description
Get HTTP status response.statusReturn the numeric status code
Set content type response.content_type = "text/html"Assign the MIME type
Read response body response.bodyFetch the whole body string
Access cookies response.cookies["name"]Read or write to the cookie jar
Stream a response response.stream.write("chunk")Send data progressively
Check if sent response.sent?Has the response been delivered?
Send a file response.send_file("path/to/file")Stream a file attachment
📦 Includes
- Rack::Response::Helpers
- ActionDispatch::Http::FilterRedirect
- ActionDispatch::Http::Cache::Response
- MonitorMixin
Represents an HTTP response generated by a controller action. Use it to retrieve the current state of the response, or customize the response. It can either represent a real HTTP response (i.e. one that is meant to be sent back to the web browser) or a TestResponse (i.e. one that is generated from integration tests).
Response is mostly a Ruby on Rails framework implementation detail, and should never be used directly in controllers. Controllers should use the methods defined in ActionController::Base instead. For example, if you want to set the HTTP response's content MIME type, then use ActionControllerBase#headers instead of Response#headers.
Nevertheless, integration tests may want to inspect controller responses in more detail, and that's when Response can be useful for application developers. Integration test methods such as ActionDispatch::Integration::Session#get and ActionDispatch::Integration::Session#post return objects of type TestResponse (which are of course also of type Response).
For example, the following demo integration test prints the body of the controller response to the console:
class DemoControllerTest < ActionDispatch::IntegrationTest
def test_print_root_path_to_console
get('/')
puts response.body
end
end
🔑 Constants
CONTENT_TYPE - [not documented]
ContentTypeHeader - [not documented]
LOCATION - [not documented]
NO_CONTENT_CODES - [not documented]
NullContentTypeHeader - [not documented]
SET_COOKIE - [not documented]
⚙️ Class methods
create
merge_default_headers
new
return_only_media_type_on_content_type
return_only_media_type_on_content_type=
🔧 Instance methods
abort
await_commit
await_sent
body
body=
body_parts
charset
charset=
close
code
commit!
committed?
content_type
content_type=
cookies
delete_header
each
get_header
has_header?
header
headers
media_type
message
prepare!
request
reset_body!
response_code
send_file
sending!
sending?
sending_file=
sent!
sent?
set_header
status
status=
status_message
stream
to_a
write
📝 Attributes
request (attr_accessor)
header (attr_reader)
headers (attr_reader)
status (attr_reader)
stream (attr_reader)
Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-01 01:22 @216.73.216.14
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)


Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format