module

Grip::Extensions::Context

Instance methods

binary(content : ::String | Bytes, content_type : ::String = "application/octet-stream") : self

Sends a response with content as binary data. Sets the Content-Type header to the specified content_type. Returns self for method chaining.

Source
client_ip
Source
client_ip=(client_ip : Socket::IPAddress | Nil)
Source
delete_req_header(key : ::String) : self

Deletes a request header by key. Returns self for method chaining.

Source
delete_resp_header(key : ::String) : self

Deletes a response header by key. Returns self for method chaining.

Source
exception
Source
exception=(exception : Exception | Nil)
Source
exec

Executes a block with self as the context. Returns the result of the block.

Source
fetch_body_params

Fetches parsed URL-encoded body parameters from the request. Returns an empty hash if no parameters are available.

Source
fetch_file_params

Fetches parsed multipart file data from the request. Returns an empty hash if no parameters are available.

Source
fetch_json_params

Fetches parsed JSON parameters from the request. Returns an empty hash if no parameters are available.

Source
fetch_path_params

Fetches parsed URL path parameters from the request. Returns an empty hash if no parameters are available.

Source
fetch_query_params

Fetches parsed GET query parameters from the request. Returns an empty hash if no parameters are available.

Source
get_req_header(key : ::String) : ::String

Gets a request header by key, raises KeyError if not found. Use get_req_header? for a nil-safe alternative.

Source
get_req_header?(key : ::String) : ::String | Nil

Gets a request header by key, returns nil if not found.

Source
get_resp_header(key : ::String) : ::String

Gets a response header by key, raises KeyError if not found.

Source
halt

Halts endpoint execution by closing the response. Returns self for method chaining.

Source
html(content : ::String, content_type : ::String = "text/html; charset=UTF-8") : self

Sends a response with content formatted as HTML. Sets the Content-Type header to the specified content_type. Returns self for method chaining.

Source
json(content, content_type : ::String = "application/json") : self

Sends a response with content formatted as JSON. Sets the Content-Type header to the specified content_type. Returns self for method chaining.

Source
merge_resp_headers(headers : Hash(::String, ::String)) : self

Merges the given headers into the response headers. Returns self for method chaining.

Source
parameters
Source
parameters=(parameters : Grip::Parsers::ParameterBox | Nil)
Source
put_req_header(key : ::String, value : ::String) : self

Assigns a request header with the given key and value. Returns self for method chaining.

Source
put_resp_header(key : ::String, value : ::String) : self

Assigns a response header with the given key and value. Returns self for method chaining.

Source
put_status(status_code : HTTP::Status = ::HTTP::Status::OK) : self

Assigns the response status code. Returns self for method chaining.

Source
put_status(status_code : Int32 = 200) : self

Assigns the response status code. Returns self for method chaining.

Source
redirect(url : ::String = "/", status_code : HTTP::Status = ::HTTP::Status::FOUND) : self

Redirects the response to the specified URL with a given status code. Returns self for method chaining.

Source
redirect(url : ::String = "/", status_code : Int32 = 302) : self
Source
send_file(path : ::String, mime_type : ::String | Nil = nil, gzip_enabled : Bool = false) : self

Sends a file as the response. path must point to an existing file. mime_type can be specified, otherwise inferred from the file extension. gzip_enabled enables gzip compression if supported. Returns self for method chaining.

Source
send_resp(content : ::String) : self

Sends a response with the given content and a status code of OK. Returns self for method chaining.

Source
stream(capacity : Int32 = 100, strategy : Grip::ServerSent::Strategy = ::Grip::ServerSent::Strategy::DropOldest) : Grip::ServerSent::Stream

Lazy-initializes the stream with custom backpressure capacity

Source
stream?

Nil-safe accessor for checking if a stream is already active

Source
text(content : ::String, content_type : ::String = "text/plain; charset=UTF-8") : self

Sends a response with content formatted as plain text. Sets the Content-Type header to the specified content_type. Returns self for method chaining.

Source