Permalink
Browse files

Break out body building into its own method

  • Loading branch information...
1 parent d34e154 commit 8309cfd31bf6053df26a268e692f414f68d1fd13 @defunkt committed Aug 29, 2012
Showing with 10 additions and 6 deletions.
  1. +10 −6 bin/djsd
View
@@ -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']

0 comments on commit 8309cfd

Please sign in to comment.