Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit af8e7498 authored by Hugo Benichi's avatar Hugo Benichi Committed by android-build-merger
Browse files

Merge "Captive portal: better detect empty responses"

am: c217f7a9

Change-Id: If6229a3a5c0ccc3575d44d11ed9f486cab35eac3
parents 2bc24e25 c217f7a9
Loading
Loading
Loading
Loading
+20 −13
Original line number Diff line number Diff line
@@ -809,19 +809,26 @@ public class NetworkMonitor extends StateMachine {
            // portal.  If it is considered a captive portal, a different sign-in URL
            // is needed (i.e. can't browse a 204).  This could be the result of an HTTP
            // proxy server.

            if (httpResponseCode == 200) {
                if (probeType == ValidationProbeEvent.PROBE_PAC) {
                    validationLog("PAC fetch 200 response interpreted as 204 response.");
                    httpResponseCode = 204;
                } else if (urlConnection.getContentLengthLong() == 0) {
                    // Consider 200 response with "Content-length=0" to not be a captive portal.
                    // There's no point in considering this a captive portal as the user cannot
                    // sign-in to an empty page. Probably the result of a broken transparent proxy.
                    // See http://b/9972012.
            if (httpResponseCode == 200 && urlConnection.getContentLength() == 0) {
                    validationLog(
                        "200 response with Content-length=0 interpreted as 204 response.");
                    httpResponseCode = 204;
                } else if (urlConnection.getContentLengthLong() == -1) {
                    // When no Content-length (default value == -1), attempt to read a byte from the
                    // response. Do not use available() as it is unreliable. See http://b/33498325.
                    if (urlConnection.getInputStream().read() == -1) {
                        validationLog("Empty 200 response interpreted as 204 response.");
                        httpResponseCode = 204;
                    }

            if (httpResponseCode == 200 && probeType == ValidationProbeEvent.PROBE_PAC) {
                validationLog("PAC fetch 200 response interpreted as 204 response.");
                httpResponseCode = 204;
                }
            }
        } catch (IOException e) {
            validationLog("Probably not a portal: exception " + e);