Zomis / Duga

Stack Exchange Chat bot
18 stars 6 forks source link

Fix unexpected method call in StackExchangeChatBot #65

Closed skiwi2 closed 9 years ago

skiwi2 commented 9 years ago

In StackExchangeChatBot there is a snippet with the following:

            @Override
            public HttpUriRequest getRedirect(
                final HttpRequest httpRequest, final HttpResponse httpResponse, final HttpContext httpContext)
                throws ProtocolException {
                httpRequest.getRequestLine().getProtocolVersion().getProtocol();
                String host = httpRequest.getFirstHeader("Host").getValue();
                String location = httpResponse.getFirstHeader("Location").getValue();
                String protocol = (httpRequest.getFirstHeader("Host").getValue().equals("openid.stackexchange.com"))
                    ? "https"
                    : "http";
                if (location.startsWith("http://") || location.startsWith("https://")) {
                    LOGGER.info("Redirecting to " + location);
                    return new HttpGet(location);
                }
                else {
                    LOGGER.info("Redirecting to " + protocol + "://" + host + location);
                    return new HttpGet(protocol + "://" + host + location);
                }
            }

Why is there a httpRequest.getRequestLine().getProtocolVersion().getProtocol(); call when the result is not saved? Are there any side effects produced by it?

Zomis commented 9 years ago

I highly doubt calling a bunch of getters causes any side-effects. I think you can safely remove that line.

Speaking of this part of the code, I believe there's a method call around there that is deprecated. Perhaps time to find a newer, more recommended solution? (I think it is the method call that creates the anonymous inner class that calls the method you show here)

skiwi2 commented 9 years ago

Nothing is deprecated as far as I know, can you investigate this more and open a new issue on that?