Class: Bane::Behaviors::Responders::HttpRefuseAllCredentials

Inherits:
Object
  • Object
show all
Defined in:
lib/bane/behaviors/responders/http_refuse_all_credentials.rb

Overview

Sends an HTTP 401 response (Unauthorized) for every request. This attempts to mimic an HTTP server by reading a line (the request) and then sending the response. This behavior responds to all incoming request URLs on the running port.

Constant Summary collapse

UNAUTHORIZED_RESPONSE_BODY =
<<EOF
<!DOCTYPE html>
<html>
  <head>
    <title>Bane Server</title>
  </head>
  <body>
    <h1>Unauthorized</h1>
  </body>
</html>
EOF

Instance Method Summary collapse

Instance Method Details

#serve(io) ⇒ Object



24
25
26
27
28
# File 'lib/bane/behaviors/responders/http_refuse_all_credentials.rb', line 24

def serve(io)
  io.gets # Read the request before responding
  response = NaiveHttpResponse.new(401, "Unauthorized", "text/html", UNAUTHORIZED_RESPONSE_BODY)
  io.write(response.to_s)
end