Browse Source

Fix headers. Fix template

Tor Hveem 10 years ago
parent
commit
8bc7acb33b
2 changed files with 5 additions and 3 deletions
  1. 4 2
      frameworks/Lua/openresty/app.lua
  2. 1 1
      frameworks/Lua/openresty/nginx.conf

+ 4 - 2
frameworks/Lua/openresty/app.lua

@@ -8,7 +8,7 @@ local sort = table.sort
 local template = require'resty.template'
 template.caching(false)
 -- Compile template, disable cache, enable plain text view to skip filesystem loading
-local view = template.compile([[<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr><tr>{% for _,f in ipairs(fortunes) do %}<tr><td>{{ f.id }}</td><td>{{ f.message }}</td></tr>{% end %}</table></body></html>]], nil, true)
+local view = template.compile([[<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>{% for _,f in ipairs(fortunes) do %}<tr><td>{{ f.id }}</td><td>{{ f.message }}</td></tr>{% end %}</table></body></html>]], nil, true)
 
 local mysqlconn = {
 	host = "DBHOSTNAME",
@@ -50,7 +50,9 @@ return {
         sort(fortunes, function(a, b)
             return a.message < b.message
         end)
-        ngx.print(view{fortunes=fortunes})
+        local res = view{fortunes=fortunes}
+        ngx.header['Content-Length'] = #res
+        ngx.print(res)
         db:set_keepalive(0, 256)
     end
 }

+ 1 - 1
frameworks/Lua/openresty/nginx.conf

@@ -22,7 +22,7 @@ http {
             content_by_lua 'ngx.print(encode({message = "Hello, World!"}))';
         }
         location /fortunes {
-            default_type "text/html";
+            default_type "text/html; charset=UTF-8";
             content_by_lua 'app.fortunes(ngx)';
         }
         location / {