511 Network Authentication Required는 네트워크 접근을 얻으려면 클라이언트가 먼저 인증해야 한다는 뜻입니다. 카페·공항·호텔의 공용 Wi-Fi에서 흔히 보는 '캡티브 포털(captive portal)' 로그인 페이지가 대표적인 사례입니다.
중요한 점은 이 코드가 최종 목적지 서버가 아니라 그 사이를 가로채는 네트워크 장비(캡티브 포털)가 반환한다는 것입니다. 즉 접속하려던 사이트의 문제가 아니라, 사용자가 아직 네트워크에 로그인/약관 동의를 하지 않은 상태를 뜻합니다.
GET http://example.com/ HTTP/1.1
Host: example.comHTTP/1.1 511 Network Authentication Required
Content-Type: text/html
<html><head><meta http-equiv="refresh" content="0; url=https://wifi.airport.example/login"></head>
<body>You need to sign in to this Wi-Fi network.</body></html>// A captive portal intercepts traffic until the client signs in
app.use((req, res) => {
if (!isAuthenticatedOnNetwork(req)) {
return res.status(511).type('html')
.send('<meta http-equiv="refresh" content="0; url=/portal/login">');
}
});