チェンジセット 1677 (default)


以下の違いを無視:
日時:
2024/08/30 16:36:30 (5週前)
更新者:
hizuya@…
ログメッセージ:
  • リクエストが Proxy 経由の場合、リクエストログになるべくリクエスト元のホスト情報を出力するようにした。
ファイル:
1個の更新

凡例:

未変更
追加
削除
  • framework/trunk/WebLibrary/Sources/WebDebugging.cs

    r1234 r1677  
    183183 
    184184            // リクエスト情報 
    185             string remotePort = request.ServerVariables["REMOTE_PORT"]; 
    186185            builder.Append(Resources.Log_Web_WebDebugging_RequestRawUrlKey, request.RawUrl); 
    187186            builder.Append(Resources.Log_Web_WebDebugging_RequestRequestTypeKey, request.RequestType); 
    188             builder.Append( 
    189                 Resources.Log_Web_WebDebugging_RequestUserHostKey, 
    190                 !string.IsNullOrEmpty(remotePort) ? request.UserHostAddress + ":" + remotePort : request.UserHostAddress); 
     187            builder.Append(Resources.Log_Web_WebDebugging_RequestUserHostKey, GetRequestUserHost(request)); 
    191188 
    192189            if (string.Equals(request.RequestType, "POST", StringComparison.OrdinalIgnoreCase)) 
     
    710707 
    711708        /// <summary> 
     709        /// リクエスト元のホスト情報を取得します。 
     710        /// </summary> 
     711        /// <param name="request">HTTP リクエスト。</param> 
     712        /// <returns> 
     713        /// リクエスト元のホスト情報。 
     714        /// </returns> 
     715        private static string GetRequestUserHost(HttpRequest request) 
     716        { 
     717            // Proxy 経由で情報が提供されている場合 
     718            string forwardedFor = request.Headers["X-Forwarded-For"]; 
     719            if (forwardedFor != null) 
     720            { 
     721                return forwardedFor; 
     722            } 
     723 
     724            string userHost = request.UserHostAddress; 
     725            string remotePort = request.ServerVariables["REMOTE_PORT"]; 
     726            return !string.IsNullOrEmpty(remotePort) 
     727                ? userHost + ":" + remotePort 
     728                : userHost; 
     729        } 
     730 
     731        /// <summary> 
    712732        /// <see cref="MaxDumpValueLength"/> の値を初期化します。 
    713733        /// </summary> 
詳しい使い方は TracChangeset を参照してください。