jimbo
jimbo

Reputation: 11042

How to set GServer DEFAULT_HOST?

Background: I'm using a ruby gem called bane which in turn uses GServer to listen for HTTP connections.

According to this other stackoverflow question, by default GServer uses the DEFAULT_HOST when listening, which is set to 127.0.0.1.

Problem: I want bane to listen on 0.0.0.0 (that is, all incoming connections, not just from locallhost). Rather than hack bane's source to allow an IP address to be specified, is there a way to override the default host in some way?

Upvotes: 0

Views: 134

Answers (1)

Casper
Casper

Reputation: 34328

Two options come to mind:

1) Override the GServer constant

In case you're not using GServer for anything else, then this approach will give you 0.0.0.0 globally.

GServer.send(:remove_const, "DEFAULT_HOST")
GServer::DEFAULT_HOST = "0.0.0.0"

2) Monkey patch Bane

# Something like this perhaps?
module Bane
  class BehaviorServer < GServer
    def initialize(port, behavior, options = {})
      super(port, options[:default_host] || GServer::DEFAULT_HOST)
      @behavior = behavior
      @options = options
      self.audit = true
    end
  end
end

Upvotes: 1

Related Questions