Skip to content

Instantly share code, notes, and snippets.

@jmahoney
Created February 25, 2020 12:15
Show Gist options
  • Save jmahoney/674580d34d02e9687dc53ea0df17d17a to your computer and use it in GitHub Desktop.
Save jmahoney/674580d34d02e9687dc53ea0df17d17a to your computer and use it in GitHub Desktop.
simple mongrel redirecting for httparty issue #582
require 'mongrel'
require 'base64'
class BasicMongrelHandler < Mongrel::HttpHandler
attr_accessor :content_type, :custom_headers, :response_body, :response_code, :preprocessor, :username, :password
def initialize
@content_type = "text/html"
@response_body = ""
@response_code = 200
@custom_headers = {}
end
def process(request, response)
instance_eval(&preprocessor) if preprocessor
reply_with(response, response_code, response_body)
end
def reply_with(response, code, response_body)
response.start(code) do |head, body|
head["Content-Type"] = content_type
custom_headers.each { |k, v| head[k] = v }
body.write(response_body)
end
end
end
server = Mongrel::HttpServer.new('0.0.0.0','6567')
landing_url = '/landing_service.html'
handler = BasicMongrelHandler.new
server.register(landing_url, handler)
redirect_url = '/landing/service'
redirect_handler = Mongrel::RedirectHandler.new('../landing_service.html')
server.register(redirect_url, redirect_handler)
server.run.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment