* luci/libs: web: fix "dispatcher.lua:167: attempt to concatenate a
[project/luci.git] / libs / web / luasrc / http.lua
index e26b3b5..17b2748 100644 (file)
@@ -81,6 +81,14 @@ function Request.formvaluetable(self, prefix)
        return vals
 end
 
+function Request.content(self)
+       if not self.parsed_input then
+               self:_parse_input()
+       end
+       
+       return self.message.content, self.message.content_length
+end
+
 function Request.getcookie(self, name)
   local c = string.gsub(";" .. (self:getenv("HTTP_COOKIE") or "") .. ";", "%s*;%s*", ";")
   local p = ";" .. name .. "=(.-);"
@@ -122,6 +130,13 @@ function close()
        end
 end
 
+--- Return the request content if the request was of unknown type.
+-- @return     HTTP request body
+-- @return     HTTP request body length
+function content()
+       return context.request:content()
+end
+
 --- Get a certain HTTP input value or a table of all input values.
 -- @param name         Name of the GET or POST variable to fetch
 -- @param noparse      Don't parse POST data before getting the value
@@ -172,6 +187,13 @@ end
 --- Set the mime type of following content data.
 -- @param mime Mimetype of following content
 function prepare_content(mime)
+       if mime == "application/xhtml+xml" then
+               if not getenv("HTTP_ACCEPT") or
+                 not getenv("HTTP_ACCEPT"):find("application/xhtml+xml", nil, true) then
+                       mime = "text/html; charset=UTF-8"
+               end
+               header("Vary", "Accept")
+       end
        header("Content-Type", mime)
 end
 
@@ -211,6 +233,7 @@ function write(content, src_err)
                        end
                        if not context.headers["cache-control"] then
                                header("Cache-Control", "no-cache")
+                               header("Expires", "0")
                        end