Permalink
Browse files

origin tweak

  • Loading branch information...
1 parent b3bcd30 commit 0841f183c19c67c08b60c552d1f749afa3a76019 @defunkt committed Jul 20, 2011
Showing with 12 additions and 4 deletions.
  1. +12 −4 bin/djsd
View
@@ -23,14 +23,22 @@ dotjs = Class.new(WEBrick::HTTPServlet::AbstractServlet) do
body << File.read(file) if File.file?(file)
response.status = body.empty? ? 204 : 200
- if request.header['origin'].length == 1 and
- request.path.length != 1 and
- request.header['origin'][0].match(request.path.gsub('/','').gsub(/\.js$/,'') + '$')
- response['Access-Control-Allow-Origin'] = request.header['origin'][0]
+ if origin = detect_origin(request)
+ response['Access-Control-Allow-Origin'] = origin
end
response['Content-Type'] = 'text/javascript'
response.body = body
end
+
+ def detect_origin(req)
+ path = req.path
+ origin = req.header['origin']
+ search = path.gsub('/','').gsub(/\.js$/,'') + '$'
+
+ if origin.length == 1 && path.length != 1 && origin[0].match(search)
+ origin[0]
+ end
+ end
end
server = WEBrick::HTTPServer.new(:Port => 3131)

0 comments on commit 0841f18

Please sign in to comment.