Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Break out body building into its own method

  • Loading branch information...
commit 8309cfd31bf6053df26a268e692f414f68d1fd13 1 parent d34e154
@defunkt authored
Showing with 10 additions and 6 deletions.
  1. +10 −6 bin/djsd
View
16 bin/djsd
@@ -15,12 +15,7 @@ require 'webrick'
dotjs = Class.new(WEBrick::HTTPServlet::AbstractServlet) do
def do_GET(request, response)
- file = File.expand_path("#{request.path.gsub('/','')}")
- default = File.expand_path("default.js")
-
- body = "// dotjs is working! //\n"
- body << File.read(default) + "\n" if File.file?(default)
- body << File.read(file) if File.file?(file)
+ body = build_body(request.path)
response.status = body.empty? ? 204 : 200
if origin = detect_origin(request)
@@ -30,6 +25,15 @@ dotjs = Class.new(WEBrick::HTTPServlet::AbstractServlet) do
response.body = body
end
+ def build_body(path)
+ file = File.expand_path("#{path.gsub('/','')}")
+ default = File.expand_path("default.js")
+
+ body = "// dotjs is working! //\n"
+ body << File.read(default) + "\n" if File.file?(default)
+ body << File.read(file) if File.file?(file)
+ end
+
def detect_origin(req)
path = req.path
origin = req.header['origin']
Please sign in to comment.
Something went wrong with that request. Please try again.