Github user solomax commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/275#discussion_r182987156
  
    --- Diff: 
wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java
 ---
    @@ -143,215 +150,133 @@ private String getUserAgentStringLc()
        }
     
        /**
    -    * When using ProxyPass, requestCycle().getHttpServletRequest(). 
getRemoteAddr() returns the IP
    -    * of the machine forwarding the request. In order to maintain the 
clients ip address, the
    -    * server places it in the <a
    -    * 
href="http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#x-headers";>X-Forwarded-For</a>
    -    * Header.
    -    *
    -    * Proxies may also mask the original client IP with tokens like 
"hidden" or "unknown".
    -    * If so, the last proxy ip address is returned.
    -    *
    -    * @param requestCycle
    -    *            the request cycle
    -    * @return remoteAddr IP address of the client, using the 
X-Forwarded-For header and defaulting
    -    *         to: getHttpServletRequest().getRemoteAddr()
    +    * Initializes the {@link WebClientInfo} user agent detection. This can 
be overridden to choose
    +    * a different detection as YAUAA 
(https://github.com/nielsbasjes/yauaa) - if you do so, you
    +    * might exclude the maven dependency from your project in favor of a 
different framework.
         */
    -   protected String getRemoteAddr(RequestCycle requestCycle)
    +   public void gatherExtendedInfo()
        {
    -           ServletWebRequest request = 
(ServletWebRequest)requestCycle.getRequest();
    -           HttpServletRequest req = request.getContainerRequest();
    -           String remoteAddr = request.getHeader("X-Forwarded-For");
    -
    -           if (remoteAddr != null)
    -           {
    -                   if (remoteAddr.contains(","))
    -                   {
    -                           // sometimes the header is of form client 
ip,proxy 1 ip,proxy 2 ip,...,proxy n ip,
    -                           // we just want the client
    -                           remoteAddr = Strings.split(remoteAddr, 
',')[0].trim();
    -                   }
    -                   try
    -                   {
    -                           // If ip4/6 address string handed over, simply 
does pattern validation.
    -                           InetAddress.getByName(remoteAddr);
    -                   }
    -                   catch (UnknownHostException e)
    -                   {
    -                           remoteAddr = req.getRemoteAddr();
    -                   }
    -           }
    -           else
    +           UserAgentAnalyzer userAgentAnalyzer = 
Application.get().getMetaData(UAA_META_DATA_KEY);
    +           if (userAgentAnalyzer == null)
                {
    -                   remoteAddr = req.getRemoteAddr();
    +                   userAgentAnalyzer = UserAgentAnalyzer.newBuilder()
    +                           .hideMatcherLoadStats()
    +                           .withCache(25000)
    +                           .build();
    +                   Application.get().setMetaData(UAA_META_DATA_KEY, 
userAgentAnalyzer);
                }
    -           return remoteAddr;
    +           detectBrowserProperties(userAgentAnalyzer);
        }
     
        /**
    -    * Initialize the client properties object
    +    * Detects browser properties like versions or the type of the browser 
and applies them to the
    +    * {@link ClientProperties}, override this method if there are errors 
within the browser /
    +    * version detection due to newer browsers
    +    * 
    +    * @param userAgentAnalyzer
    +    *            the user agent analyzer to detect browsers and versions
         */
    -   private void init()
    +   protected void detectBrowserProperties(UserAgentAnalyzer 
userAgentAnalyzer)
        {
    -           setInternetExplorerProperties();
    -           setOperaProperties();
    -           setMozillaProperties();
    -           setKonquerorProperties();
    -           setChromeProperties();
    -           setEdgeProperties();
    -           setSafariProperties();
     
    -           log.debug("determined user agent: {}", properties);
    -   }
    +           nl.basjes.parse.useragent.UserAgent parsedUserAgent = 
userAgentAnalyzer
    +                   .parse(getUserAgent());
    +           String userAgentName = parsedUserAgent.getValue("AgentName");
     
    -   /**
    -    * sets the konqueror specific properties
    -    */
    -   private void setKonquerorProperties()
    -   {
    -           
properties.setBrowserKonqueror(UserAgent.KONQUEROR.matches(getUserAgent()));
    +           // Konqueror
    +           
properties.setBrowserKonqueror(UserAgent.KONQUEROR.getUaStrings().contains(userAgentName));
     
    -           if (properties.isBrowserKonqueror())
    -           {
    -                   // e.g.: Mozilla/5.0 (compatible; Konqueror/4.2; Linux) 
KHTML/4.2.96 (like Gecko)
    -                   
setMajorMinorVersionByPattern("konqueror/(\\d+)\\.(\\d+)");
    -           }
    -   }
    +           // Chrome
    +           
properties.setBrowserChrome(UserAgent.CHROME.getUaStrings().contains(userAgentName));
     
    -   /**
    -    * sets the chrome specific properties
    -    */
    -   private void setChromeProperties()
    -   {
    -           
properties.setBrowserChrome(UserAgent.CHROME.matches(getUserAgent()));
    +           // Edge
    +           
properties.setBrowserEdge(UserAgent.EDGE.getUaStrings().contains(userAgentName));
     
    -           if (properties.isBrowserChrome())
    -           {
    -                   // e.g.: Mozilla/5.0 (Windows NT 6.1) 
AppleWebKit/534.24 (KHTML, like Gecko)
    -// Chrome/12.0.702.0 Safari/534.24
    -                   setMajorMinorVersionByPattern("chrome/(\\d+)\\.(\\d+)");
    -           }
    -   }
    +           // Safari
    +           
properties.setBrowserSafari(UserAgent.SAFARI.getUaStrings().contains(userAgentName));
     
    -   /**
    -    * sets the Edge specific properties
    -    */
    -   private void setEdgeProperties()
    -   {
    -           
properties.setBrowserEdge(UserAgent.EDGE.matches(getUserAgent()));
    +           // Opera
    +           
properties.setBrowserOpera(UserAgent.OPERA.getUaStrings().contains(userAgentName));
    +
    +           // Internet Explorer
    +           properties.setBrowserInternetExplorer(
    +                   
UserAgent.INTERNET_EXPLORER.getUaStrings().contains(userAgentName));
     
    -           if (properties.isBrowserEdge())
    +           // FireFox
    +           boolean isFireFox = 
UserAgent.FIREFOX.getUaStrings().contains(userAgentName);
    +           if (isFireFox)
                {
    -                   // e.g.: Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
AppleWebKit/537.36 (KHTML, like Gecko)
    -                   // Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063
    -                   setMajorMinorVersionByPattern("edge/(\\d+)\\.(\\d+)");
    +                   properties.setBrowserMozillaFirefox(true);
    +                   properties.setBrowserMozilla(true);
                }
    -   }
    -
    -   /**
    -    * sets the safari specific properties
    -    */
    -   private void setSafariProperties()
    -   {
    -           
properties.setBrowserSafari(UserAgent.SAFARI.matches(getUserAgent()));
    -
    -           if (properties.isBrowserSafari())
    +           else
                {
    -                   String userAgent = getUserAgentStringLc();
    --- End diff --
    
    `getUserAgentStringLc` is private and not used anymore


---

Reply via email to