Class: Bane::Behaviors::HttpRefuseAllCredentials

Inherits:
BasicBehavior show all
Defined in:
lib/bane/behaviors.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 =
"<!DOCTYPE html>\n<html>\n  <head>\n    <title>Bane Server</title>\n  </head>\n  <body>\n    <h1>Unauthorized</h1>\n  </body>\n</html>\n"

Instance Method Summary collapse

Methods inherited from BasicBehavior

inherited, simple_name

Instance Method Details

#serve(io) ⇒ Object



162
163
164
165
166
# File 'lib/bane/behaviors.rb', line 162

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