Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8514

Show
Ignore:
Timestamp:
12/30/07 11:16:15 (8 months ago)
Author:
tobie
Message:

prototype: jstest.rb cleanup.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/prototype/trunk/test/lib/jstest.rb

    r8512 r8514  
    208208    res['Expires'] = Time.now - 100**4 
    209209  end 
     210end 
     211 
     212class BasicServlet < WEBrick::HTTPServlet::AbstractServlet 
     213  def do_GET(req, res) 
     214    prevent_caching(res) 
     215    res['Content-Type'] = "text/plain" 
     216     
     217    req.query.each do |k, v| 
     218      res[k] = v unless k == 'responseBody' 
     219    end 
     220    res.body = req.query["responseBody"] 
     221     
     222    raise WEBrick::HTTPStatus::OK 
     223  end 
     224   
     225  def do_POST(req, res) 
     226    do_GET(req, res) 
     227  end 
     228end 
     229 
     230class SlowServlet < BasicServlet 
     231  def do_GET(req, res) 
     232    sleep(2) 
     233    super 
     234  end 
     235end 
     236 
     237class DownServlet < BasicServlet 
     238  def do_GET(req, res) 
     239    res.fail_silently 
     240  end 
     241end 
     242 
     243class InspectionServlet < BasicServlet 
     244  def do_GET(req, res) 
     245    prevent_caching(res) 
     246    res['Content-Type'] = "application/json" 
     247    res.body = req.to_json 
     248    raise WEBrick::HTTPStatus::OK 
     249  end 
     250end 
     251 
     252class NonCachingFileHandler < WEBrick::HTTPServlet::FileHandler 
     253  def do_GET(req, res) 
     254    super 
     255    set_default_content_type(res, req.path) 
     256    prevent_caching(res) 
     257  end 
    210258   
    211259  def set_default_content_type(res, path) 
     
    216264      else 'text/plain' 
    217265    end 
    218   end 
    219 end 
    220  
    221 class BasicServlet < WEBrick::HTTPServlet::AbstractServlet 
    222   def do_GET(req, res) 
    223     set_default_content_type(res, req.path) 
    224     prevent_caching(res) 
    225      
    226     req.query.each do |k, v| 
    227       res[k] = v unless k == 'responseBody' 
    228     end 
    229     res.body = req.query["responseBody"] 
    230      
    231     raise WEBrick::HTTPStatus::OK 
    232   end 
    233    
    234   def do_POST(req, res) 
    235     do_GET(req, res) 
    236   end 
    237 end 
    238  
    239 class SlowServlet < BasicServlet 
    240   def do_GET(req, res) 
    241     sleep(2) 
    242     super 
    243   end 
    244 end 
    245  
    246 class DownServlet < BasicServlet 
    247   def do_GET(req, res) 
    248     res.fail_silently 
    249   end 
    250 end 
    251  
    252 class InspectionServlet < BasicServlet 
    253   def do_GET(req, res) 
    254     prevent_caching(res) 
    255     res['Content-Type'] = "application/json" 
    256     res.body = req.to_json 
    257     raise WEBrick::HTTPStatus::OK 
    258   end 
    259 end 
    260  
    261 class NonCachingFileHandler < WEBrick::HTTPServlet::FileHandler 
    262   def do_GET(req, res) 
    263     super 
    264     set_default_content_type(res, req.path) 
    265     prevent_caching(res) 
    266266  end 
    267267end