1- using StackifyLib . Models ;
2- using System ;
1+ using System ;
32using System . Collections . Generic ;
43using System . Linq ;
5- using System . Threading . Tasks ;
64using Microsoft . AspNetCore . Http ;
75using Microsoft . AspNetCore . Routing ;
8- using Microsoft . Extensions . Primitives ;
96using Microsoft . Extensions . DependencyInjection ;
7+ using Microsoft . Extensions . Primitives ;
8+ using StackifyLib . Models ;
109
1110namespace StackifyLib . AspNetCore
1211{
@@ -22,67 +21,43 @@ internal static void WebRequestDetail_SetWebRequestDetail(WebRequestDetail detai
2221 var context = Configure . ServiceProvider ? . GetService < IHttpContextAccessor > ( ) ? . HttpContext ;
2322
2423 if ( context == null )
24+ {
2525 return ;
26+ }
2627
2728 Load ( context , detail ) ;
2829 }
2930
3031 private static void Load ( HttpContext context , WebRequestDetail detail )
3132 {
3233 if ( context == null || context . Request == null )
34+ {
3335 return ;
36+ }
3437
35- HttpRequest request = context . Request ;
38+ var request = context . Request ;
3639
3740 try
3841 {
3942 detail . HttpMethod = request . Method ;
40-
41- detail . UserIPAddress = context ? . Connection ? . RemoteIpAddress ? . ToString ( ) ;
42-
43-
44- //if (context.Items != null && context.Items.Contains("Stackify.ReportingUrl"))
45- //{
46- // ReportingUrl = context.Items["Stackify.ReportingUrl"].ToString();
47- //}
48-
49-
50- if ( request . IsHttps )
51- {
52- detail . RequestProtocol = "https" ;
53- }
54- else
55- {
56- detail . RequestProtocol = "http" ;
57- }
58- detail . RequestUrl = detail . RequestProtocol + "//" + request . Host + request . Path ;
59-
60-
43+ detail . UserIPAddress = context . Connection ? . RemoteIpAddress ? . ToString ( ) ;
44+ detail . RequestProtocol = request . IsHttps ? "https" : "http" ;
45+ detail . RequestUrl = $ "{ detail . RequestProtocol } //{ request . Host } { request . Path } ";
6146 detail . MVCAction = context . GetRouteValue ( "action" ) ? . ToString ( ) ;
6247 detail . MVCController = context . GetRouteValue ( "controller" ) ? . ToString ( ) ;
6348
64- if ( ! string . IsNullOrEmpty ( detail . MVCAction ) && ! string . IsNullOrEmpty ( detail . MVCController ) )
49+ if ( string . IsNullOrEmpty ( detail . MVCAction ) == false && string . IsNullOrEmpty ( detail . MVCController ) == false )
6550 {
66- detail . ReportingUrl = detail . MVCController + "." + detail . MVCAction ;
51+ detail . ReportingUrl = $ " { detail . MVCController } . { detail . MVCAction } " ;
6752 }
68-
69-
70- //if (request.AppRelativeCurrentExecutionFilePath != null)
71- //{
72- // RequestUrlRoot = request.AppRelativeCurrentExecutionFilePath.TrimStart('~');
73- //}
74-
7553 }
7654 catch ( Exception )
7755 {
78-
56+ // ignored
7957 }
8058
81-
82-
8359 try
8460 {
85-
8661 if ( request . QueryString != null )
8762 {
8863 detail . QueryString = ToKeyValues ( request . Query , null , null ) ;
@@ -95,12 +70,12 @@ private static void Load(HttpContext context, WebRequestDetail detail)
9570 Config . ErrorHeaderBadKeys = new List < string > ( ) ;
9671 }
9772
98- if ( ! Config . ErrorHeaderBadKeys . Contains ( "cookie" ) )
73+ if ( Config . ErrorHeaderBadKeys . Contains ( "cookie" ) == false )
9974 {
10075 Config . ErrorHeaderBadKeys . Add ( "cookie" ) ;
10176 }
10277
103- if ( ! Config . ErrorHeaderBadKeys . Contains ( "authorization" ) )
78+ if ( Config . ErrorHeaderBadKeys . Contains ( "authorization" ) == false )
10479 {
10580 Config . ErrorHeaderBadKeys . Add ( "authorization" ) ;
10681 }
@@ -117,66 +92,33 @@ private static void Load(HttpContext context, WebRequestDetail detail)
11792 {
11893 detail . PostData = ToKeyValues ( request . Form , null , null ) ;
11994 }
120-
121- //sessions return a byte array...
122- //if (context.Session != null && Config.CaptureSessionVariables && Config.ErrorSessionGoodKeys.Any())
123- //{
124- // SessionData = new Dictionary<string, string>();
125-
126- // foreach (var key in Config.ErrorSessionGoodKeys)
127- // {
128- // SessionData[key] = context.Session
129- // }
130-
131-
132- //}
133-
134- //if (Config.CaptureErrorPostdata)
135- //{
136- // var contentType = context.Request.Headers["Content-Type"];
137-
138- // if (contentType != "text/html" && contentType != "application/x-www-form-urlencoded" &&
139- // context.Request.RequestType != "GET")
140- // {
141- // int length = 4096;
142- // string postBody = new StreamReader(context.Request.InputStream).ReadToEnd();
143- // if (postBody.Length < length)
144- // {
145- // length = postBody.Length;
146- // }
147-
148- // PostDataRaw = postBody.Substring(0, length);
149- // }
150- //}
15195 }
15296 catch ( Exception )
15397 {
98+ // ignored
15499 }
155100 }
156101
157- //IEnumerable<KeyValuePair<string, StringValues>>
158- //IEnumerable<KeyValuePair<string, string>>
159102 internal static Dictionary < string , string > ToKeyValues ( IEnumerable < KeyValuePair < string , StringValues > > collection , List < string > goodKeys , List < string > badKeys )
160103 {
161- //var keys = collection.Keys;
162104 var items = new Dictionary < string , string > ( ) ;
163105
164- foreach ( var item in collection )
106+ foreach ( KeyValuePair < string , StringValues > item in collection )
165107 {
166- string key = item . Key ;
108+ var key = item . Key ;
109+
167110 try
168111 {
169112 object val = item . Value . ToString ( ) ;
170113
171- if ( val != null && ! string . IsNullOrWhiteSpace ( val . ToString ( ) ) && items . ContainsKey ( key ) )
114+ if ( val != null && string . IsNullOrWhiteSpace ( val . ToString ( ) ) == false && items . ContainsKey ( key ) )
172115 {
173116 AddKey ( key , val . ToString ( ) , items , goodKeys , badKeys ) ;
174117 }
175-
176118 }
177119 catch ( Exception )
178120 {
179-
121+ // ignored
180122 }
181123 }
182124
@@ -185,25 +127,24 @@ internal static Dictionary<string, string> ToKeyValues(IEnumerable<KeyValuePair<
185127
186128 internal static Dictionary < string , string > ToKeyValues ( IEnumerable < KeyValuePair < string , string > > collection , List < string > goodKeys , List < string > badKeys )
187129 {
188- //var keys = collection.Keys;
189130 var items = new Dictionary < string , string > ( ) ;
190131
191- foreach ( var item in collection )
132+ foreach ( KeyValuePair < string , string > item in collection )
192133 {
193- string key = item . Key ;
134+ var key = item . Key ;
135+
194136 try
195137 {
196138 object val = item . Value ;
197139
198- if ( val != null && ! string . IsNullOrWhiteSpace ( val . ToString ( ) ) && items . ContainsKey ( key ) )
140+ if ( val != null && string . IsNullOrWhiteSpace ( val . ToString ( ) ) == false && items . ContainsKey ( key ) )
199141 {
200142 AddKey ( key , val . ToString ( ) , items , goodKeys , badKeys ) ;
201143 }
202-
203144 }
204145 catch ( Exception )
205146 {
206-
147+ // ignored
207148 }
208149 }
209150
@@ -218,14 +159,15 @@ internal static void AddKey(string key, string value, Dictionary<string, string>
218159 dictionary [ key ] = "X-MASKED-X" ;
219160 return ;
220161 }
162+
221163 //if not in the good key list, return
222164 //if good key list is empty, we let it take it
223- else if ( goodKeys != null && goodKeys . Any ( ) && ! goodKeys . Any ( x => x . Equals ( key , StringComparison . CurrentCultureIgnoreCase ) ) )
165+ if ( goodKeys != null && goodKeys . Any ( ) && goodKeys . Any ( x => x . Equals ( key , StringComparison . CurrentCultureIgnoreCase ) ) == false )
224166 {
225167 return ;
226168 }
227169
228170 dictionary [ key ] = value ;
229171 }
230172 }
231- }
173+ }
0 commit comments