From 66a2a206634a496e3bba4173df97624a9fbc92f9 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Tue, 19 Sep 2017 15:36:16 +0200 Subject: [PATCH] Implement request host, path and content_type access --- lib/nanoserve.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/nanoserve.rb b/lib/nanoserve.rb index 5ab4559..36b3dbc 100644 --- a/lib/nanoserve.rb +++ b/lib/nanoserve.rb @@ -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{(?[A-Z]+)\s+(?\S+)\s+(?HTTP/\d+.\d+)$}