Mercurial Hosting > luan
comparison src/luan/modules/http/Http.luan @ 1743:792268dce5ec
http push security
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 09 Nov 2022 18:33:09 -0700 |
parents | 9713f7fd50b3 |
children |
comparison
equal
deleted
inserted
replaced
1742:d778f1f2598a | 1743:792268dce5ec |
---|---|
18 local case_insensitive = Table.case_insensitive or error() | 18 local case_insensitive = Table.case_insensitive or error() |
19 local Package = require "luan:Package.luan" | 19 local Package = require "luan:Package.luan" |
20 local String = require "luan:String.luan" | 20 local String = require "luan:String.luan" |
21 local lower = String.lower or error() | 21 local lower = String.lower or error() |
22 local trim = String.trim or error() | 22 local trim = String.trim or error() |
23 local regex = String.regex or error() | |
23 local Time = require "luan:Time.luan" | 24 local Time = require "luan:Time.luan" |
24 local time_format = Time.format or error() | 25 local time_format = Time.format or error() |
25 local Boot = require "luan:Boot.luan" | 26 local Boot = require "luan:Boot.luan" |
26 local LuanJava = require "java:luan.Luan" | 27 local LuanJava = require "java:luan.Luan" |
27 local Request = require "java:goodjava.webserver.Request" | 28 local Request = require "java:goodjava.webserver.Request" |
203 local msg = "Internal Server Error\n\n"..err | 204 local msg = "Internal Server Error\n\n"..err |
204 return Response.errorResponse( Status.INTERNAL_SERVER_ERROR, msg ) | 205 return Response.errorResponse( Status.INTERNAL_SERVER_ERROR, msg ) |
205 end | 206 end |
206 | 207 |
207 Http.domain = nil -- set in domain specific cases | 208 Http.domain = nil -- set in domain specific cases |
209 local domain_regex = nil | |
210 function Http.set_domain(domain) | |
211 Http.domain = domain or error() | |
212 domain_regex = regex( [[^https?://]]..domain..[[(/|:)]] ) | |
213 end | |
208 | 214 |
209 Http.is_serving = false | 215 Http.is_serving = false |
210 | 216 |
211 function Http.format_date(date) | 217 function Http.format_date(date) |
212 return time_format(date,"EEE, dd MMM yyyy HH:mm:ss z","GMT") | 218 return time_format(date,"EEE, dd MMM yyyy HH:mm:ss z","GMT") |
213 end | 219 end |
214 | 220 |
215 Http.push = ServerSentEvents.writeMessage -- ( url, message ) | 221 local sse_push = ServerSentEvents.writeMessage |
222 function Http.push( url, message ) | |
223 domain_regex==nil or domain_regex.matches(url) or error "can't push to another domain" | |
224 sse_push(url,message) | |
225 end | |
216 | 226 |
217 return Http | 227 return Http |