module Grip::Extensions::Context
Direct including types
Defined in:
grip/extensions/context.crInstance Method Summary
-
#binary(content : ::String | Bytes, content_type : ::String = "application/octet-stream") : self
Sends a response with content as binary data.
- #client_ip : Socket::IPAddress | Nil
- #client_ip=(client_ip : Socket::IPAddress | Nil)
-
#delete_req_header(key : ::String) : self
Deletes a request header by key.
-
#delete_resp_header(key : ::String) : self
Deletes a response header by key.
- #exception : Exception | Nil
- #exception=(exception : Exception | Nil)
-
#exec(&)
Executes a block with self as the context.
-
#fetch_body_params : URI::Params
Fetches parsed URL-encoded body parameters from the request.
-
#fetch_file_params : Hash(::String, Parsers::FileUpload)
Fetches parsed multipart file data from the request.
-
#fetch_json_params : Hash(::String, Parsers::ParameterBox::AllParamTypes)
Fetches parsed JSON parameters from the request.
-
#fetch_path_params : Hash(::String, ::String)
Fetches parsed URL path parameters from the request.
-
#fetch_query_params : URI::Params
Fetches parsed GET query parameters from the request.
-
#get_req_cookie(key : ::String) : HTTP::Cookie | Nil
Gets a cookie from the request by key, returns nil if not found.
-
#get_req_header(key : ::String) : ::String
Gets a request header by key, raises KeyError if not found.
-
#get_req_header?(key : ::String) : ::String | Nil
Gets a request header by key, returns nil if not found.
-
#get_resp_header(key : ::String) : ::String
Gets a response header by key, raises KeyError if not found.
-
#halt : self
Halts endpoint execution by closing the response.
-
#html(content : ::String, content_type : ::String = "text/html; charset=UTF-8") : self
Sends a response with content formatted as HTML.
-
#json(content, content_type : ::String = "application/json") : self
Sends a response with content formatted as JSON.
-
#merge_resp_headers(headers : Hash(::String, ::String)) : self
Merges the given headers into the response headers.
- #parameters : Grip::Parsers::ParameterBox | Nil
- #parameters=(parameters : Grip::Parsers::ParameterBox | Nil)
-
#put_req_header(key : ::String, value : ::String) : self
Assigns a request header with the given key and value.
-
#put_resp_cookie(key : ::String, value : ::String) : self
Sets a response cookie with the given key and value as a string.
-
#put_resp_cookie(cookie : HTTP::Cookie) : self
Sets a response cookie with the given cookie object.
-
#put_resp_header(key : ::String, value : ::String) : self
Assigns a response header with the given key and value.
-
#put_status(status_code : HTTP::Status = HTTP::Status::OK) : self
Assigns the response status code.
-
#put_status(status_code : Int32 = 200) : self
Assigns the response status code.
-
#redirect(url : ::String = "/", status_code : HTTP::Status = HTTP::Status::FOUND) : self
Redirects the response to the specified URL with a given status code.
- #redirect(url : ::String = "/", status_code : Int32 = 302) : self
-
#send_file(path : ::String, mime_type : ::String | Nil = nil, gzip_enabled : Bool = false) : self
Sends a file as the response.
-
#send_resp(content : ::String) : self
Sends a response with the given content and a status code of OK.
-
#text(content : ::String, content_type : ::String = "text/plain; charset=UTF-8") : self
Sends a response with content formatted as plain text.
Instance Method Detail
Sends a response with content as binary data.
Sets the Content-Type header to the specified content_type
.
Returns self for method chaining.
Deletes a request header by key. Returns self for method chaining.
Deletes a response header by key. Returns self for method chaining.
Fetches parsed URL-encoded body parameters from the request. Returns an empty hash if no parameters are available.
Fetches parsed multipart file data from the request. Returns an empty hash if no parameters are available.
Fetches parsed JSON parameters from the request. Returns an empty hash if no parameters are available.
Fetches parsed URL path parameters from the request. Returns an empty hash if no parameters are available.
Fetches parsed GET query parameters from the request. Returns an empty hash if no parameters are available.
Gets a cookie from the request by key, returns nil if not found.
Gets a request header by key, raises KeyError if not found.
Use #get_req_header?
for a nil-safe alternative.
Gets a request header by key, returns nil if not found.
Gets a response header by key, raises KeyError if not found.
Halts endpoint execution by closing the response. Returns self for method chaining.
Sends a response with content formatted as HTML.
Sets the Content-Type header to the specified content_type
.
Returns self for method chaining.
Sends a response with content formatted as JSON.
Sets the Content-Type header to the specified content_type
.
Returns self for method chaining.
Merges the given headers into the response headers. Returns self for method chaining.
Assigns a request header with the given key and value. Returns self for method chaining.
Sets a response cookie with the given key and value as a string. Returns self for method chaining.
Sets a response cookie with the given cookie object. Returns self for method chaining.
Assigns a response header with the given key and value. Returns self for method chaining.
Assigns the response status code. Returns self for method chaining.
Assigns the response status code. Returns self for method chaining.
Redirects the response to the specified URL with a given status code. Returns self for method chaining.
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.
Sends a response with the given content and a status code of OK. Returns self for method chaining.
Sends a response with content formatted as plain text.
Sets the Content-Type header to the specified content_type
.
Returns self for method chaining.