Sha256: a1d6d0eafe86c474385fe44150576fbf3b3e92e7b19ceceb41df9a7c1c5d96f1

Contents?: true

Size: 1.6 KB

Versions: 68

Compression:

Stored size: 1.6 KB

Contents

# Overwriting methods from Rack
module Rack
  class Request
    def host_with_port
      if forwarded = @env["HTTP_X_FORWARDED_HOST"]
        # Rails.logger.info "\n\nContour::Fixes Rack::Request::host_with_port"
        # Rails.logger.info "@env[HTTP_X_FORWARDED_HOST]: #{@env["HTTP_X_FORWARDED_HOST"]} USING: #{forwarded.split(/,\s?/).first}\n\n"
        # forwarded.split(/,\s?/).last
        # changed forwarded to first since we don't want the internal IP.
        forwarded.split(/,\s?/).first
      else
        @env['HTTP_HOST'] || "#{@env['SERVER_NAME'] || @env['SERVER_ADDR']}:#{@env['SERVER_PORT']}"
      end
    end
  end


  # Required as Rack 1.5.x series removed the default content type of text/html for some unknown reason, something about "adhering to standards for HTTP 1.0 and 1.1 protocols"
  # Was removed in this commit: https://github.com/rack/rack/commit/3623d04526b953a63bfb3e72de2d6920a042563f#L2L21
  class Response
    def initialize(body=[], status=200, header={})
      @status = status.to_i
      @header = Utils::HeaderHash.new("Content-Type" => "text/html").merge(header) # This is the modified line that requires Content-Type set to text/html.

      @chunked = "chunked" == @header['Transfer-Encoding']
      @writer  = lambda { |x| @body << x }
      @block   = nil
      @length  = 0

      @body = []

      if body.respond_to? :to_str
        write body.to_str
      elsif body.respond_to?(:each)
        body.each { |part|
          write part.to_s
        }
      else
        raise TypeError, "stringable or iterable required"
      end

      yield self  if block_given?
    end
  end
end

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
contour-3.0.1 lib/contour/fixes/rack.rb
contour-3.0.1.rc lib/contour/fixes/rack.rb
contour-3.0.0 lib/contour/fixes/rack.rb
contour-3.0.0.rc lib/contour/fixes/rack.rb
contour-3.0.0.beta1 lib/contour/fixes/rack.rb
contour-2.7.0 lib/contour/fixes/rack.rb
contour-2.7.0.beta1 lib/contour/fixes/rack.rb
contour-2.6.0 lib/contour/fixes/rack.rb
contour-2.6.0.rc lib/contour/fixes/rack.rb
contour-2.6.0.beta8 lib/contour/fixes/rack.rb
contour-2.6.0.beta7 lib/contour/fixes/rack.rb
contour-2.6.0.beta6 lib/contour/fixes/rack.rb
contour-2.6.0.beta5 lib/contour/fixes/rack.rb
contour-2.6.0.beta4 lib/contour/fixes/rack.rb
contour-2.6.0.beta3 lib/contour/fixes/rack.rb
contour-2.6.0.beta2 lib/contour/fixes/rack.rb
contour-2.6.0.beta1 lib/contour/fixes/rack.rb
contour-2.5.0 lib/contour/fixes/rack.rb
contour-2.5.0.beta1 lib/contour/fixes/rack.rb
contour-2.4.0 lib/contour/fixes/rack.rb