require 'crystal_ext/gems' # enshure domain has no www. except if there's custom subdomain module Crystal # class UrlWithWww < StandardError # end module Processors class EnsureNoWww < Processor def call workspace.params.must_be.defined if workspace.params.html? and url_with_www? redirect_without_www else next_processor.call end end protected def uri @uri ||= Uri.parse workspace.request.url end def url_with_www? uri.host =~ /^www\./ end def redirect_without_www uri.host = uri.host.sub(/^www\./, '') url = uri.to_s response = workspace.response response.status = 301 response.headers['Location'] = url response.body = %(
You are being redirected.) end end end end