Implement request host, path and content_type access

This commit is contained in:
Loic Nageleisen 2017-09-19 15:36:16 +02:00
parent dd5001cb7c
commit 66a2a20663

View file

@ -98,6 +98,14 @@ module NanoServe
@body = +''.encode('ASCII-8BIT')
end
def host
@headers['host']
end
def path
@uri.path
end
def params
Hash[*@uri.query.split('&').map { |kv| kv.split('=') }.flatten]
end
@ -132,6 +140,10 @@ module NanoServe
@headers.key?('content-length')
end
def content_type
@headers['content-type']
end
private
REQ_RE = %r{(?<method>[A-Z]+)\s+(?<path>\S+)\s+(?<version>HTTP/\d+.\d+)$}