Captive portal: better detect empty responses
am: cb4aa4d412
Change-Id: I64a006f6bb83dc588b108395d54189bb401c83ff
This commit is contained in:
@@ -809,19 +809,26 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
// portal. If it is considered a captive portal, a different sign-in URL
|
// 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
|
// is needed (i.e. can't browse a 204). This could be the result of an HTTP
|
||||||
// proxy server.
|
// proxy server.
|
||||||
|
if (httpResponseCode == 200) {
|
||||||
// Consider 200 response with "Content-length=0" to not be a captive portal.
|
if (probeType == ValidationProbeEvent.PROBE_PAC) {
|
||||||
// There's no point in considering this a captive portal as the user cannot
|
validationLog("PAC fetch 200 response interpreted as 204 response.");
|
||||||
// sign-in to an empty page. Probably the result of a broken transparent proxy.
|
httpResponseCode = 204;
|
||||||
// See http://b/9972012.
|
} else if (urlConnection.getContentLengthLong() == 0) {
|
||||||
if (httpResponseCode == 200 && urlConnection.getContentLength() == 0) {
|
// Consider 200 response with "Content-length=0" to not be a captive portal.
|
||||||
validationLog("Empty 200 response interpreted as 204 response.");
|
// There's no point in considering this a captive portal as the user cannot
|
||||||
httpResponseCode = 204;
|
// sign-in to an empty page. Probably the result of a broken transparent proxy.
|
||||||
}
|
// See http://b/9972012.
|
||||||
|
validationLog(
|
||||||
if (httpResponseCode == 200 && probeType == ValidationProbeEvent.PROBE_PAC) {
|
"200 response with Content-length=0 interpreted as 204 response.");
|
||||||
validationLog("PAC fetch 200 response interpreted as 204 response.");
|
httpResponseCode = 204;
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
validationLog("Probably not a portal: exception " + e);
|
validationLog("Probably not a portal: exception " + e);
|
||||||
|
|||||||
Reference in New Issue
Block a user