Module: Wpxf::Net::HttpServer
Overview
Provides basic, single threaded HTTP server functionality.
Instance Method Summary collapse
-
#http_server_bind_address ⇒ String
The address the HTTP server is bound to.
-
#http_server_bind_port ⇒ Integer
The port the HTTP server is listening on.
-
#http_server_thread ⇒ Thread
Thread that the server runs on when in non-blocking mode.
-
#initialize ⇒ Object
Initialize a new instance of HttpServer.
-
#js_ajax_download ⇒ String
The AJAX download helper script.
-
#js_ajax_post ⇒ String
The AJAX post helper script.
-
#js_post ⇒ String
The JS post helper script.
-
#on_http_request(path, params, headers) ⇒ String, Hash
Invoked when a HTTP request is made to the server.
-
#start_http_server(non_block = false) ⇒ Object
Start the HTTP server.
-
#stop_http_server ⇒ Object
Stop the HTTP server after it has finished processing the current request.
Instance Method Details
#http_server_bind_address ⇒ String
Returns the address the HTTP server is bound to.
33 34 35 |
# File 'lib/wpxf/net/http_server.rb', line 33 def http_server_bind_address normalized_option_value('http_server_bind_address') end |
#http_server_bind_port ⇒ Integer
Returns the port the HTTP server is listening on.
38 39 40 |
# File 'lib/wpxf/net/http_server.rb', line 38 def http_server_bind_port normalized_option_value('http_server_bind_port') end |
#http_server_thread ⇒ Thread
Returns thread that the server runs on when in non-blocking mode.
98 99 100 |
# File 'lib/wpxf/net/http_server.rb', line 98 def http_server_thread @http_server_thread end |
#initialize ⇒ Object
Initialize a new instance of Wpxf::Net::HttpServer.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/wpxf/net/http_server.rb', line 11 def initialize super ([ StringOption.new( name: 'http_server_bind_address', desc: 'Address to bind the HTTP server to', default: '0.0.0.0', required: true ), PortOption.new( name: 'http_server_bind_port', desc: 'Port for the HTTP server to listen on', default: 80, required: true ) ]) @http_server_kill_switch = false end |
#js_ajax_download ⇒ String
Returns the AJAX download helper script.
54 55 56 |
# File 'lib/wpxf/net/http_server.rb', line 54 def js_ajax_download File.read(File.join(Wpxf.data_directory, 'js', 'ajax_download.js')) end |
#js_ajax_post ⇒ String
Returns the AJAX post helper script.
59 60 61 |
# File 'lib/wpxf/net/http_server.rb', line 59 def js_ajax_post File.read(File.join(Wpxf.data_directory, 'js', 'ajax_post.js')) end |
#js_post ⇒ String
Returns the JS post helper script.
64 65 66 |
# File 'lib/wpxf/net/http_server.rb', line 64 def js_post File.read(File.join(Wpxf.data_directory, 'js', 'post.js')) end |
#on_http_request(path, params, headers) ⇒ String, Hash
Invoked when a HTTP request is made to the server.
51 |
# File 'lib/wpxf/net/http_server.rb', line 51 def on_http_request(path, params, headers) end |
#start_http_server(non_block = false) ⇒ Object
Start the HTTP server.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/wpxf/net/http_server.rb', line 70 def start_http_server(non_block = false) @tcp_server = TCPServer.new(http_server_bind_address, http_server_bind_port) emit_info "Started HTTP server on #{http_server_bind_address}:"\ "#{http_server_bind_port}" if non_block @http_server_thread = Thread.new do _http_server_loop end else _http_server_loop end end |
#stop_http_server ⇒ Object
Stop the HTTP server after it has finished processing the current request.
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/wpxf/net/http_server.rb', line 85 def stop_http_server return false if @is_stopping @is_stopping = true emit_info 'Stopping HTTP server...', true @http_server_kill_switch = true @http_server_thread&.exit @tcp_server.close if !@tcp_server.nil? && !@tcp_server.closed? emit_info 'HTTP server stopped' @is_stopping = false end |