CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/http/server_client.rb
Views: 11704
1
# -*- coding: binary -*-
2
require 'rex/socket'
3
4
5
module Rex
6
module Proto
7
module Http
8
9
###
10
#
11
# Runtime extension of the HTTP clients that connect to the server.
12
#
13
###
14
module ServerClient
15
16
#
17
# Initialize a new request instance.
18
#
19
def init_cli(server)
20
self.request = Request.new
21
self.server = server
22
self.keepalive = false
23
end
24
25
#
26
# Resets the parsing state.
27
#
28
def reset_cli
29
self.request.reset
30
end
31
32
#
33
# Transmits a response and adds the appropriate headers.
34
#
35
def send_response(response)
36
# Set the connection to close or keep-alive depending on what the client
37
# can support.
38
response['Connection'] = (keepalive) ? 'Keep-Alive' : 'close'
39
40
# Add any other standard response headers.
41
server.add_response_headers(response)
42
43
# Send it off.
44
put(response.to_s)
45
end
46
47
#
48
# The current request context.
49
#
50
attr_accessor :request
51
#
52
# Boolean that indicates whether or not the connection supports keep-alive.
53
#
54
attr_accessor :keepalive
55
#
56
# A reference to the server the client is associated with.
57
#
58
attr_accessor :server
59
60
end
61
62
end
63
end
64
end
65
66