Changeset 24890 for lang

Show
Ignore:
Timestamp:
11/26/08 04:35:02 (4 years ago)
Author:
drry
Message:
  • User-Agent ヘッダから不正な文字を除去しました。
  • 正規表現を修正しました。
  • ほか。
Location:
lang/ruby/enokidu_antenna
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/enokidu_antenna/enokidu.rb

    r24822 r24890  
    3232      @timeout = options[:timeout] || 30 
    3333      @debug   = options[:debug] || false 
    34       @request = Request.new(:timeout => @timeout, :debug   => @debug) 
     34      @request = Request.new(:timeout => @timeout, :debug  => @debug) 
    3535    end 
    3636 
    3737    def detective(options = {}) 
    38       page    = options[:page] 
     38      page = options[:page] 
    3939 
    4040      page.body ||= '' 
     
    7676  class Request 
    7777    def initialize(options = {}) 
    78       @http_header = {'User-Agent' => Enokidu::UserAgent::NAME, 'Connection' => 'close'} 
     78      @http_header = { 
     79        'User-Agent' => "#{Enokidu::UserAgent::NAME}/#{Enokidu::UserAgent::VERSION}".gsub(/:+/, ''), 
     80        'Connection' => 'close' 
     81      } 
    7982      @timeout = options[:timeout] || 30 
    8083      @debug   = options[:debug] || false 
     
    114117 
    115118        # ロケーションが空または不完全な場合 
    116         if !location.empty? and !location.match(%r[^http://]) 
     119        if !location.empty? and !location.match(%r[^https?://]) 
    117120          uri = URI.parse(old_uri) 
    118121          path, query = location.split('?') 
     
    136139      if page.title.empty? 
    137140        debug_print "get page title" 
    138         page.title = body.scan(/<title>([^<]*)/im).to_s.strip 
     141        page.title = body.scan(/<title(?:\s[^>]*)?>\s*([^<]*)/im).to_s.rstrip 
    139142        page.title = 'no title' if page.title.empty? 
    140143      end 
     
    144147      else 
    145148        body 
    146       end.gsub(/<[^>]*>|\s|\n/, '') 
     149      end.gsub(/<[^>]*>|\s+/, '') 
    147150 
    148151      # 更新チェック 
     
    189192      end 
    190193 
    191       # Etag で更新チェック 
     194      # ETag で更新チェック 
    192195      if !lm and etag and page.etag != etag 
    193196        page.etag = etag 
     
    196199      end 
    197200 
    198       # Last-Modified も Etag も使えない 
     201      # Last-Modified も ETag も使えない 
    199202      raise InvalidHeadResponse unless lm or etag 
    200203 
  • lang/ruby/enokidu_antenna/enokidu_test.rb

    r24822 r24890  
    4646    before_modified_at = page.last_modified_at 
    4747    page = detective(:page => page) 
    48      
     48 
    4949    assert page.updated? 
    5050    assert before_modified_at < page.last_modified_at