W3cubDocs

/Crystal

class HTTP::Request

Overview

An HTTP request.

It serves both to perform requests by an HTTP::Client and to represent requests received by an HTTP::Server.

A request always holds an IO as a body. When creating a request with a String or Bytes its body will be a IO::Memory wrapping these, and the Content-Length header will be set appropriately.

Defined in:

http/request.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(method : String, resource : String, headers : Headers? = nil, body : String | Bytes | IO | Nil = nil, version = "HTTP/1.1")Source

Class Method Detail

def self.from_io(io, *, max_request_line_size : Int32 = HTTP::MAX_REQUEST_LINE_SIZE, max_headers_size : Int32 = HTTP::MAX_HEADERS_SIZE) : HTTP::Request | HTTP::Status | NilSource

Returns a HTTP::Request instance if successfully parsed, nil on EOF or HTTP::Status otherwise.

Instance Method Detail

def body : IO?Source

def body=(body : Nil)Source

def body=(body : IO)Source

def body=(body : Bytes)Source

def body=(body : String)Source

def content_lengthSource

def content_length=(length : Int)Source

def cookiesSource

Returns a convenience wrapper around querying and setting cookie related headers, see HTTP::Cookies.

def headers : HeadersSource

def headers=(headers : Headers)Source

def hostSource

Returns request host from headers.

def host_with_portSource

Returns request host with port from headers.

def if_match : Array(String)?Source

def if_none_match : Array(String)?Source

def ignore_body?Source

def keep_alive?Source

def method : StringSource

def method=(method : String)Source

def pathSource

Returns the request's path component.

def path=(path)Source

Sets request's path component.

def querySource

Lazily parses and returns the request's query component.

def query=(value)Source

Sets request's query component.

def query_paramsSource

Returns a convenience wrapper around querying and setting query params, see HTTP::Params.

def remote_address : RemoteAddressTypeSource

The network address that sent the request to an HTTP server.

HTTP::Server will try to fill this property, and its value will have a format like "IP:port", but this format is not guaranteed. Middlewares can overwrite this value.

This property is not used by HTTP::Client.

def remote_address=(remote_address : RemoteAddressType)Source

The network address that sent the request to an HTTP server.

HTTP::Server will try to fill this property, and its value will have a format like "IP:port", but this format is not guaranteed. Middlewares can overwrite this value.

This property is not used by HTTP::Client.

def resourceSource

def to_io(io)Source

def version : StringSource

def version=(version : String)Source

© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/HTTP/Request.html