Method: HTTPTools::Builder.response
- Defined in:
- lib/http_tools/builder.rb
.response(code, headers = {}) ⇒ Object
:call-seq: Builder.response(status, headers={}) -> string
Returns a HTTP status line and headers. Status can be a HTTP status code as an integer, or a HTTP status message as a lowercase, underscored symbol.
Builder.response(200, "Content-Type" => "text/html")
#=> "HTTP/1.1 200 ok\r\nContent-Type: text/html\r\n\r\n"
Builder.response(:internal_server_error)
#=> "HTTP/1.1 500 Internal Server Error\r\n\r\n"
To send multiple headers with the same name:
Builder.response(:ok, "Set-Cookie" => ["a=b", "c=d"])
Builder.response(:ok, "Set-Cookie" => "a=b\nc=d")
25 26 27 |
# File 'lib/http_tools/builder.rb', line 25 def response(code, headers={}) "HTTP/1.1 #{STATUS_LINES[code] || code}\r\n#{format_headers(headers)}\r\n" end |