トップ «前の日記(2023-03-25) 最新 次の日記(2023-04-01)» 編集

Orz日記 by Akio Morita

ToDo:

  • 15 SAD Fit[]回りの障害事例の解析
  • 10 smart pointer版PEGクラスの再実装(Left Recursionまわり)
2006|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|06|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|07|08|09|10|11|12|
2013|01|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|06|07|08|10|12|
2016|01|02|03|05|06|08|10|11|
2017|01|02|03|04|05|06|07|09|10|11|12|
2018|01|02|03|04|06|07|08|09|10|11|12|
2019|01|03|04|05|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|03|04|05|06|07|08|09|

2023-03-30 [長年日記]

_ [tDiary]weather plugin続き

weather pluginの不具合の件だが、直した!

  • 2018年 3月から問題が発生した原因は、情報サイト側のhttpsリダイレクト開始
  • エラーになるのは、pluginの実装不備
    • wrong number of arguments (given 2, expected 3)の原因は、同plugin内のWeather.fetchの実装で、Net::HTTPRedirection時にfetchメソッドを再帰呼び出しする際に3引数必要なところ 2引数で呼び出している
      • 第3引数 headerを追加
    • weather plugin Weather.fetchがhttps://に未対応
      • URI schmeが httpsのとき、Net::HTTP.start前に Net::HTTP.use_ssl=trueする (session = Net::HTTP.new(...)した後、use_ssl操作後に session.start do ... endさせる)
      • リダイレクトの遅延を避けるため、STATION_URL_TEMPLATEhttps://に切り替える
Index: misc/plugin/weather.rb
===================================================================
--- misc/plugin/weather.rb      (.../vender/tDiary.org/tdiary-core/stable/misc/plugin/weather.rb)       (revision 759)
+++ misc/plugin/weather.rb      (.../trunk/public:amorita/diary/misc/plugin/weather.rb) (revision 759)
@@ -64,7 +64,7 @@
 - first draft
 =end

-require 'net/http'
+require 'net/https'
 require 'cgi'
 require 'timeout'
 require 'date' # DateTime.strptime
@@ -154,7 +154,7 @@
        AVIATIONWEATHER_STATION_REGEXP = %r|(?:aviationweather.gov/adds/metars/\?.*station_ids=)([A-Z]{4,4})\b|
        NOAA_STATION_REGEXP = %r|(?:weather.noaa.gov/weather/current/)([A-Z]{4,4})\b|
        RAW_STATION_REGEXP = %r|\A([A-Z]{4,4})\z|
-       STATION_URL_TEMPLATE = "http://www.aviationweather.gov/adds/metars/?station_ids=%s&std_trans=translated&chk_metars=on&hoursStr=most+recent+only"
+       STATION_URL_TEMPLATE = "https://www.aviationweather.gov/adds/metars/?station_ids=%s&std_trans=translated&chk_metars=on&hoursStr=most+recent+only"

        def Weather::extract_station_id(url)
                        [AVIATIONWEATHER_STATION_REGEXP, NOAA_STATION_REGEXP, RAW_STATION_REGEXP].each do |r|
@@ -292,12 +292,14 @@
                px_host, px_port = (@conf['proxy'] || '').split( /:/ )
                px_port = 80 if px_host and !px_port
                u = URI::parse( url )
-               Net::HTTP::Proxy( px_host, px_port ).start( u.host, u.port ) do |http|
+               session = Net::HTTP::Proxy( px_host, px_port ).new( u.host, u.port )
+               session.use_ssl = u.scheme == "https"
+               session.start do |http|
                        case res = http.get( u.request_uri, header )
                        when Net::HTTPSuccess
                                res.body
                        when Net::HTTPRedirection
-                               fetch( res['location'], limit - 1 )
+                               fetch( res['location'], limit - 1, header )
                        else
                                raise ArgumentError, res.error!
                        end

カテゴリー: Admin | Emacs | EPICS | Fortran | FreeBSD | GCC | hgsubversion | IPv6 | KEKB | LHC | Lisp | LLVM | MADX | Ryzen | SAD | samba | tDiary | unix | WWW | YaSAI | お仕事 | イベント | 出張 | 宴会 | 数学 | 艦これ | 買いもの | 追記 | 雑記