Changeset 6490
- Timestamp:
- 02/10/08 15:18:03 (5 years ago)
- Location:
- lang/ruby/chokan/trunk
- Files:
-
- 2 modified
-
config.yaml.sample (modified) (1 diff)
-
plugins/uri_information.rb (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/chokan/trunk/config.yaml.sample
r1533 r6490 19 19 20 20 UriInformation: 21 accept_scheme :21 accept_schemes: 22 22 - http 23 23 - https -
lang/ruby/chokan/trunk/plugins/uri_information.rb
r5866 r6490 10 10 class UriInformation < Chokan::PluginBase 11 11 MAX_REDIRECT = 10 12 HEADER = {13 "User-Agent" => "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.1 1) Gecko/20071127 Firefox/2.0.0.11",12 HEADERS = { 13 "User-Agent" => "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12", 14 14 "Accept" => "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", 15 15 } 16 16 17 def initialize(config, chokan)18 super19 @uri = /(#{URI.regexp(@config['accept_scheme']).to_s})/20 end21 22 17 def on_privmsg(prefix, channel, message) 23 18 @channel = channel 24 message.scan(@uri) do |uri| 19 URI.extract(messages, @config['accept_schemes'] || 20 @config['accept_scheme']) do |uri| 25 21 begin 26 uri = uri[0]27 22 uri = URI(uri) 28 23 mes = nil … … 95 90 } 96 91 data = data.collect {|k,v| "#{k}=#{URI.escape(v, /[^-.!~*'()\w]/n)}" }.join("&") 97 res = http.post(login_uri.request_uri, data, HEADER )92 res = http.post(login_uri.request_uri, data, HEADERS) 98 93 if res.key?("set-cookie") 99 94 res["set-cookie"].split(/\s*,\s*/).each do |c| … … 146 141 end 147 142 148 def http(uri, header =HEADER, limit=MAX_REDIRECT)143 def http(uri, headers=HEADERS, limit=MAX_REDIRECT) 149 144 return "Redirect loop?: last:#{uri}" if limit <= 0 150 145 … … 154 149 http.use_ssl = (uri.scheme == "https") 155 150 http.start do |http| 156 r = http.head(uri.request_uri, header )151 r = http.head(uri.request_uri, headers) 157 152 log r.code.inspect 158 153 case r.code … … 160 155 case r["Content-Type"] 161 156 when /html/ 162 ret = html(http.get(uri.request_uri, header .merge({157 ret = html(http.get(uri.request_uri, headers.merge({ 163 158 "Range" => "0-5000" 164 159 }))) 165 160 when /image/ 166 ret = image(http.get(uri.request_uri, header ))161 ret = image(http.get(uri.request_uri, headers)) 167 162 else 168 163 if r["Content-Length"] … … 178 173 if auth 179 174 auth = "Basic " + ["#{auth["user"]}:#{auth["pass"]}"].pack("m") 180 ret = http(uri, header .update({'Authorization' => auth}), limit-1)175 ret = http(uri, headers.update({'Authorization' => auth}), limit-1) 181 176 else 182 177 ret = realm … … 185 180 loc = URI(r["Location"]) 186 181 loc = uri + loc if loc.relative? 187 ret = http(loc, header , limit-1)182 ret = http(loc, headers, limit-1) 188 183 else 189 184 ret = "[#{r.code} #{r.message}]"
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)