Created
February 25, 2020 12:15
-
-
Save jmahoney/674580d34d02e9687dc53ea0df17d17a to your computer and use it in GitHub Desktop.
simple mongrel redirecting for httparty issue #582
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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