diff src/luan/modules/http/Http.luan @ 1607:fa066aaa068c

nginx caching
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 30 Apr 2021 20:23:28 -0600
parents c922446f53aa
children a37ffe2d1b14
line wrap: on
line diff
--- a/src/luan/modules/http/Http.luan	Tue Apr 20 18:06:50 2021 -0600
+++ b/src/luan/modules/http/Http.luan	Fri Apr 30 20:23:28 2021 -0600
@@ -15,6 +15,7 @@
 local Table = require "luan:Table.luan"
 local clear = Table.clear or error()
 local java_to_table_deep = Table.java_to_table_deep or error()
+local case_insensitive = Table.case_insensitive or error()
 local Package = require "luan:Package.luan"
 local String = require "luan:String.luan"
 local lower = String.lower or error()
@@ -75,7 +76,7 @@
 	if java == nil then
 		this.method = "GET"
 		this.scheme = "http"
-		this.headers = {}
+		this.headers = case_insensitive{}
 		this.parameters = {}
 		this.cookies = {}
 	else
@@ -88,13 +89,13 @@
 		this.path = java.path or error()
 		this.protocol = java.protocol or error()
 		this.scheme = java.scheme or error()
-		this.headers = java_to_table_deep(java.headers)
+		this.headers = case_insensitive(java_to_table_deep(java.headers))
 		this.parameters = java_to_table_deep(java.parameters,java_to_table_shallow)
 		this.cookies = java_to_table_deep(java.cookies)
 	end
 
 	function this.url()
-		return this.scheme.."://"..this.headers["host"]..this.raw_path
+		return this.scheme.."://"..this.headers["Host"]..this.raw_path
 	end
 
 	return this
@@ -115,7 +116,7 @@
 
 	function this.reset()
 		this.java = Response.new()
-		this.headers = {}
+		this.headers = case_insensitive{}
 		this.status = STATUS.OK
 		this.writer = nil
 	end
@@ -124,14 +125,14 @@
 
 	function this.send_redirect(location)
 		this.status = STATUS.FOUND
-		this.headers["location"] = location
+		this.headers["Location"] = location
 	end
 
 	function this.send_error(status,msg)
 		this.reset()
 		this.status = status
 		if msg ~= nil then
-			this.headers["content-type"] = "text/plain; charset=utf-8"
+			this.headers["Content-Type"] = "text/plain; charset=utf-8"
 			local writer = this.text_writer()
 			writer.write(msg)
 		end
@@ -183,7 +184,6 @@
 	java.status = Status.getStatus(response.status)
 	for name, value in pairs(response.headers) do
 		type(name)=="string" or "header name must be string"
-		name = lower(name)
 		value = LuanJava.toJava(value)
 		java.headers.put(name,value)
 	end
@@ -209,7 +209,7 @@
 Http.is_serving = false
 
 function Http.format_date(date)
-	return time_format(date,"EEE, dd MMM yyyy HH:mm:ss 'GMT'","GMT")
+	return time_format(date,"EEE, dd MMM yyyy HH:mm:ss z","GMT")
 end
 
 return Http