3333
3434import static com .perimeterx .utils .Constants .BREACHED_ACCOUNT_KEY_NAME ;
3535import static com .perimeterx .utils .PXCommonUtils .cookieHeadersNames ;
36+ import static com .perimeterx .utils .PXCommonUtils .logTime ;
3637
3738/**
3839 * PXContext - Populate relevant data from HttpRequest
@@ -226,20 +227,20 @@ public PXContext(final HttpServletRequest request, final IPProvider ipProvider,
226227 }
227228
228229 private void initContext (final HttpServletRequest request , PXConfiguration pxConfiguration ) {
229- this .headers = PXCommonUtils .getHeadersFromRequest ( request );
230+ this .headers = logTime ( " PXCommonUtils.getHeadersFromRequest" , () -> PXCommonUtils . getHeadersFromRequest ( request ) );
230231
231232 if (headers .containsKey (Constants .MOBILE_SDK_AUTHORIZATION_HEADER ) || headers .containsKey (Constants .MOBILE_SDK_TOKENS_HEADER )) {
232233 logger .debug (PXLogger .LogReason .DEBUG_MOBILE_SDK_DETECTED );
233234 this .isMobileToken = true ;
234235 this .cookieOrigin = Constants .HEADER_ORIGIN ;
235236 }
236- parseCookies ( request , isMobileToken );
237- generateLoginData ( request , pxConfiguration );
237+ logTime ( " parseCookies" , () -> parseCookies ( request , isMobileToken ) );
238+ logTime ( " generateLoginData" , () -> generateLoginData ( request , pxConfiguration ) );
238239
239240 this .firstPartyRequest = false ;
240241 this .userAgent = request .getHeader ("user-agent" );
241242 this .uri = request .getRequestURI ();
242- this .fullUrl = extractURL ( request ); //full URL with query string
243+ this .fullUrl = logTime ( " extractURL" , () -> extractURL ( request ) ); //full URL with query string
243244 this .blockReason = BlockReason .NONE ;
244245 this .passReason = PassReason .NONE ;
245246 this .s2sErrorReasonInfo = new S2SErrorReasonInfo ();
@@ -257,9 +258,9 @@ private void initContext(final HttpServletRequest request, PXConfiguration pxCon
257258 Function <? super HttpServletRequest , ? extends CustomParameters > customParametersExtraction = pxConfiguration .getCustomParametersExtraction ();
258259 try {
259260 if (customParametersExtraction != null ) {
260- this .customParameters = customParametersExtraction .apply ( this .request );
261+ this .customParameters = logTime ( " customParametersExtraction.apply" , () -> customParametersExtraction . apply ( this .request ) );
261262 } else {
262- this .customParameters = customParametersProvider .buildCustomParameters ( pxConfiguration , this );
263+ this .customParameters = logTime ( " customParametersProvider.buildCustomParameters" , () -> customParametersProvider . buildCustomParameters ( pxConfiguration , this ) );
263264 }
264265 } catch (Exception e ) {
265266 logger .debug ("failed to extract custom parameters from custom function" , e );
@@ -327,41 +328,46 @@ private void parseCookies(HttpServletRequest request, boolean isMobileToken) {
327328 List <RawCookieData > tokens = new ArrayList <>();
328329 List <RawCookieData > originalTokens = new ArrayList <>();
329330 if (isMobileToken ) {
330- headerParser = new MobileCookieHeaderParser ();
331+ logTime ("anonymousParseCookiesMobile" , () -> {
332+ // This was changed because it is not possible to override a value inside a function.
333+ HeaderParser hp = new MobileCookieHeaderParser ();
331334
332- String tokensHeader = request .getHeader (Constants .MOBILE_SDK_TOKENS_HEADER );
333- tokens .addAll (headerParser .createRawCookieDataList (tokensHeader ));
335+ String tokensHeader = request .getHeader (Constants .MOBILE_SDK_TOKENS_HEADER );
336+ tokens .addAll (hp .createRawCookieDataList (tokensHeader ));
334337
335- String authCookieHeader = request .getHeader (Constants .MOBILE_SDK_AUTHORIZATION_HEADER );
336- tokens .addAll (headerParser .createRawCookieDataList (authCookieHeader ));
338+ String authCookieHeader = request .getHeader (Constants .MOBILE_SDK_AUTHORIZATION_HEADER );
339+ tokens .addAll (hp .createRawCookieDataList (authCookieHeader ));
337340
338- String originalTokensHeader = request .getHeader (Constants .MOBILE_SDK_ORIGINAL_TOKENS_HEADER );
339- originalTokens .addAll (headerParser .createRawCookieDataList (originalTokensHeader ));
341+ String originalTokensHeader = request .getHeader (Constants .MOBILE_SDK_ORIGINAL_TOKENS_HEADER );
342+ originalTokens .addAll (hp .createRawCookieDataList (originalTokensHeader ));
340343
341- String originalTokenHeader = request .getHeader (Constants .MOBILE_SDK_ORIGINAL_TOKEN_HEADER );
342- originalTokens .addAll (headerParser .createRawCookieDataList (originalTokenHeader ));
344+ String originalTokenHeader = request .getHeader (Constants .MOBILE_SDK_ORIGINAL_TOKEN_HEADER );
345+ originalTokens .addAll (hp .createRawCookieDataList (originalTokenHeader ));
343346
344- this .tokens = tokens ;
345- if (!originalTokens .isEmpty ()) {
346- this .originalTokens = originalTokens ;
347- }
347+ this .tokens = tokens ;
348+ if (!originalTokens .isEmpty ()) {
349+ this .originalTokens = originalTokens ;
350+ }
348351
349- ObjectMapper mapper = new ObjectMapper ();
350- this .pxde = mapper .createObjectNode ();
351- this .pxdeVerified = true ;
352+ ObjectMapper mapper = new ObjectMapper ();
353+ this .pxde = mapper .createObjectNode ();
354+ this .pxdeVerified = true ;
355+ });
352356 } else {
353- Cookie [] cookies = request .getCookies ();
354- String [] cookieHeaders = cookieHeadersNames (getPxConfiguration ())
355- .stream ()
356- .map (request ::getHeader )
357- .toArray (String []::new );
358- this .requestCookieNames = CookieNamesExtractor .extractCookieNames (cookies );
359- setVidAndPxhd (cookies );
360- tokens .addAll (headerParser .createRawCookieDataList (cookieHeaders ));
361- this .tokens = tokens ;
362- DataEnrichmentCookie deCookie = headerParser .getRawDataEnrichmentCookie (this .tokens , this .pxConfiguration .getCookieKey ());
363- this .pxde = deCookie .getJsonPayload ();
364- this .pxdeVerified = deCookie .isValid ();
357+ logTime ("anonymousParseCookiesElse" , () -> {
358+ Cookie [] cookies = request .getCookies ();
359+ String [] cookieHeaders = cookieHeadersNames (getPxConfiguration ())
360+ .stream ()
361+ .map (request ::getHeader )
362+ .toArray (String []::new );
363+ this .requestCookieNames = CookieNamesExtractor .extractCookieNames (cookies );
364+ setVidAndPxhd (cookies );
365+ tokens .addAll (headerParser .createRawCookieDataList (cookieHeaders ));
366+ this .tokens = tokens ;
367+ DataEnrichmentCookie deCookie = headerParser .getRawDataEnrichmentCookie (this .tokens , this .pxConfiguration .getCookieKey ());
368+ this .pxde = deCookie .getJsonPayload ();
369+ this .pxdeVerified = deCookie .isValid ();
370+ });
365371 }
366372 }
367373
0 commit comments