Class OverSIP::WebSocket::HttpRequest
An OverSIP::WebSocket::HttpRequest
instance is provided by OverSIP when a client attempts to establish a WebSocket connection.
Having the following HTTP GET request (a WebSocket handshake request) stored into a variable http_request
(an OverSIP::WebSocket::HttpRequest
instance), OverSIP provides the methods below for retrieving information from the request:
GET /sip-call?user_id=uyads75jsd&key=kh7Shjs#some-fragment HTTP/1.1
Host: ws.example.Com.
Upgrade: WebSocket
Connection: keep-Alive , Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-protocol: sip, xmpp
Sec-WebSocket-protocol: h323
Origin: http://www.example.Com
Sec-WebSocket-Version: 13
Cookie: name=value; name2=value2
X-Custom-Header: foo
x-custom-header: BAZ
Class instance methods
uri
Gets the Request-URI (String
) of the request.
Example
http_request.uri
#=> "/sip-call?user_id=uyads75jsd&key=kh7Shjs#some-fragment"
uri_path
Gets the Request-URI path component (String
) of the request.
Example
http_request.uri_path
#=> "/sip-call"
uri_query
Gets the Request-URI query component (String
) of the request. It could be nil
.
Example
http_request.uri_query
#=> "user_id=uyads75jsd&key=kh7Shjs"
uri_fragment
Gets the Request-URI fragment component (String
) of the request. It could be nil
.
Example
http_request.uri_fragment
#=> "some-fragment"
host
Gets the normalized host (String
) in the Host header. It could be nil
:
Example
http_request.host
#=> "ws.example.com"
port
Gets the normalized port (Fixnum
) in the Host header. It could be nil
:
Example
http_request.port
#=> nil
hdr_origin
Gets the normalized value (String
) of the Origin header. It could be nil
.
Example
http_request.hdr_origin
#=> "www.example.com"
hdr_connection
Gets an Array
with the lowcase value(s) (Strings
) of the Connection header.
Examples
http_request.hdr_connection
#=> ["keep-alive", "upgrade"]
hdr_upgrade
Gets the lowcase value (String
) of the Upgrade header.
Example
http_request.hdr_upgrade
#=> "websocket"
hdr_sec_websocket_version
Gets the value (Fixnum
) of the Sec-WebSocket-Version header.
Example
http_request.hdr_sec_websocket_version
#=> 13
hdr_sec_websocket_key
Gets the value (String
) of the Sec-WebSocket-Key header.
Example
http_request.hdr_sec_websocket_key
#=> "dGhlIHNhbXBsZSBub25jZQ=="
hdr_sec_websocket_protocol
Gets an Array
with the lowcase value(s) (Strings
) of the Sec-WebSocket-Protocol header(s).
Example
http_request.hdr_sec_websocket_protocol
#=> ["sip", "xmpp", "h323"]
[header_field]
Gets an Array
with the value(s) (Strings
) of the given header field.
Parameters
header_field
- The name of the header to search for. It’s automatically normalized.
Examples
http_request["Cookie"]
#=> ["name=value; name2=value2"]
http_request["X-CUSTOM-HEADER"]
#=> ["foo", "BAZ"]