Module: Tilia::Http::MessageInterface

Included in:
Message, RequestInterface, ResponseInterface
Defined in:
lib/tilia/http/message_interface.rb

Overview

The MessageInterface is the base interface that’s used by both the RequestInterface and ResponseInterface.

Instance Method Summary collapse

Instance Method Details

#add_header(_name, _value) ⇒ void

This method returns an undefined value.

Adds a HTTP header.

This method will not overwrite any existing HTTP header, but instead add another value. Individual values can be retrieved with getHeadersAsArray.

Parameters:

  • name (String)
  • value (String)


116
117
# File 'lib/tilia/http/message_interface.rb', line 116

def add_header(_name, _value)
end

#add_headers(_headers) ⇒ void

This method returns an undefined value.

Adds a new set of HTTP headers.

Any existing headers will not be overwritten.

Parameters:

  • array

    headers



125
126
# File 'lib/tilia/http/message_interface.rb', line 125

def add_headers(_headers)
end

#bodyObject

Returns the message body, as it’s internal representation.

This could be either a string or a stream.

Returns:

  • resource|string



29
30
# File 'lib/tilia/http/message_interface.rb', line 29

def body
end

#body=(_body) ⇒ void

This method returns an undefined value.

Updates the body resource with a new stream.

Parameters:

  • resource

    body



36
37
# File 'lib/tilia/http/message_interface.rb', line 36

def body=(_body)
end

#body_as_streamObject

Returns the body as a readable stream resource.

Note that the stream may not be rewindable, and therefore may only be read once.

Returns:

  • resource



12
13
# File 'lib/tilia/http/message_interface.rb', line 12

def body_as_stream
end

#body_as_stringString

Returns the body as a string.

Note that because the underlying data may be based on a stream, this method could only work correctly the first time.

Returns:

  • (String)


21
22
# File 'lib/tilia/http/message_interface.rb', line 21

def body_as_string
end

#header(_name) ⇒ String?

Returns a specific HTTP header, based on it’s name.

The name must be treated as case-insensitive. If the header does not exist, this method must return null.

If a header appeared more than once in a HTTP request, this method will concatenate all the values with a comma.

Note that this not make sense for all headers. Some, such as ‘Set-Cookie` cannot be logically combined with a comma. In those cases you should use header_as_array.

Parameters:

  • name (String)

Returns:

  • (String, nil)


68
69
# File 'lib/tilia/http/message_interface.rb', line 68

def header(_name)
end

#header?(_name) ⇒ Boolean

Will return true or false, depending on if a HTTP header exists.

Parameters:

  • name (String)

Returns:

  • (Boolean)

    bool



51
52
# File 'lib/tilia/http/message_interface.rb', line 51

def header?(_name)
end

#header_as_array(_name) ⇒ String

Returns a HTTP header as an array.

For every time the HTTP header appeared in the request or response, an item will appear in the array.

If the header did not exists, this method will return an empty array.

Parameters:

  • name (String)

Returns:

  • (String)


80
81
# File 'lib/tilia/http/message_interface.rb', line 80

def header_as_array(_name)
end

#headersObject

Returns all the HTTP headers as an array.

Every header is returned as an array, with one or more values.

Returns:

  • array



44
45
# File 'lib/tilia/http/message_interface.rb', line 44

def headers
end

#http_versionString

Returns the HTTP version.

Returns:

  • (String)


150
151
# File 'lib/tilia/http/message_interface.rb', line 150

def http_version
end

#http_version=(_version) ⇒ void

This method returns an undefined value.

Sets the HTTP version.

Should be 1.0 or 1.1.

Parameters:

  • version (String)


144
145
# File 'lib/tilia/http/message_interface.rb', line 144

def http_version=(_version)
end

#remove_header(_name) ⇒ Object

Removes a HTTP header.

The specified header name must be treated as case-insenstive. This method should return true if the header was successfully deleted, and false if the header did not exist.

Returns:

  • bool



135
136
# File 'lib/tilia/http/message_interface.rb', line 135

def remove_header(_name)
end

#update_header(_name, _value) ⇒ void

This method returns an undefined value.

Updates a HTTP header.

The case-sensitity of the name value must be retained as-is.

If the header already existed, it will be overwritten.

Parameters:

  • name (String)
  • value (String, Array<String>)


92
93
# File 'lib/tilia/http/message_interface.rb', line 92

def update_header(_name, _value)
end

#update_headers(_headers) ⇒ void

This method returns an undefined value.

Sets a new set of HTTP headers.

The headers array should contain headernames for keys, and their value should be specified as either a string or an array.

Any header that already existed will be overwritten.

Parameters:

  • array

    headers



104
105
# File 'lib/tilia/http/message_interface.rb', line 104

def update_headers(_headers)
end