Skip to content

Commit

Permalink
Move the ServerClient code into a dedicated file
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroSteiner committed Nov 22, 2023
1 parent 98e6bae commit e9d6bab
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 55 deletions.
53 changes: 0 additions & 53 deletions lib/rex/proto/http/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,6 @@ module Rex
module Proto
module Http

###
#
# Runtime extension of the HTTP clients that connect to the server.
#
###
module ServerClient

#
# Initialize a new request instance.
#
def init_cli(server)
self.request = Request.new
self.server = server
self.keepalive = false
end

#
# Resets the parsing state.
#
def reset_cli
self.request.reset
end

#
# Transmits a response and adds the appropriate headers.
#
def send_response(response)
# Set the connection to close or keep-alive depending on what the client
# can support.
response['Connection'] = (keepalive) ? 'Keep-Alive' : 'close'

# Add any other standard response headers.
server.add_response_headers(response)

# Send it off.
put(response.to_s)
end

#
# The current request context.
#
attr_accessor :request
#
# Boolean that indicates whether or not the connection supports keep-alive.
#
attr_accessor :keepalive
#
# A reference to the server the client is associated with.
#
attr_accessor :server

end

###
#
# Acts as an HTTP server, processing requests and dispatching them to
Expand Down
64 changes: 64 additions & 0 deletions lib/rex/proto/http/server_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- coding: binary -*-
require 'rex/socket'


module Rex
module Proto
module Http

###
#
# Runtime extension of the HTTP clients that connect to the server.
#
###
module ServerClient

#
# Initialize a new request instance.
#
def init_cli(server)
self.request = Request.new
self.server = server
self.keepalive = false
end

#
# Resets the parsing state.
#
def reset_cli
self.request.reset
end

#
# Transmits a response and adds the appropriate headers.
#
def send_response(response)
# Set the connection to close or keep-alive depending on what the client
# can support.
response['Connection'] = (keepalive) ? 'Keep-Alive' : 'close'

# Add any other standard response headers.
server.add_response_headers(response)

# Send it off.
put(response.to_s)
end

#
# The current request context.
#
attr_accessor :request
#
# Boolean that indicates whether or not the connection supports keep-alive.
#
attr_accessor :keepalive
#
# A reference to the server the client is associated with.
#
attr_accessor :server

end

end
end
end
2 changes: 0 additions & 2 deletions modules/auxiliary/server/capture/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Current source: https://github.com/rapid7/metasploit-framework
##

require 'rex/proto/http/server'

class MetasploitModule < Msf::Auxiliary
include Msf::Exploit::Remote::TcpServer
include Msf::Auxiliary::Report
Expand Down

0 comments on commit e9d6bab

Please sign in to comment.