<commit_before>require 'net/http'
require 'net/https'

module Rack
  class ReverseProxy
    def initialize(app = nil, &b)
      @app = app || lambda {|env| [404, [], []] }
      @matchers = []
      @global_options = {:preserve_host => true, :matching => :all, :verify_ssl => true}
      instance_eval &b if block_given?
    end

    def call(env)
      rackreq = Rack::Request.new(env)
      matcher = get_matcher rackreq.fullpath
      return @app.call(env) if matcher.nil?

      uri = matcher.get_uri(rackreq.fullpath,env)
      all_opts = @global_options.dup.merge(matcher.options)
      headers = Rack::Utils::HeaderHash.new
      env.each { |key, value|
        if key =~ /HTTP_(.*)/
          headers[$1] = value
        end
      }
      headers['HOST'] = uri.host if all_opts[:preserve_host]
 
      session = Net::HTTP.new(uri.host, uri.port)
      session.read_timeout=all_opts[:timeout] if all_opts[:timeout]

      session.use_ssl = (uri.scheme == 'https')
      if uri.scheme == 'https' && all_opts[:verify_ssl]
        session.verify_mode = OpenSSL::SSL::VERIFY_PEER
      else
        # DO NOT DO THIS IN PRODUCTION !!!
        session.verify_mode = OpenSSL::SSL::VERIFY_NONE
      end
      session.start { |http|<commit_msg>Add x_forwarded_host, which will forward the original Host header using the X-Forwarded-Host request header<commit_after>require 'net/http'
require 'net/https'

module Rack
  class ReverseProxy
    def initialize(app = nil, &b)
      @app = app || lambda {|env| [404, [], []] }
      @matchers = []
      @global_options = {:preserve_host => true, :matching => :all, :verify_ssl => true}
      instance_eval &b if block_given?
    end

    def call(env)
      rackreq = Rack::Request.new(env)
      matcher = get_matcher rackreq.fullpath
      return @app.call(env) if matcher.nil?

      uri = matcher.get_uri(rackreq.fullpath,env)
      all_opts = @global_options.dup.merge(matcher.options)
      headers = Rack::Utils::HeaderHash.new
      env.each { |key, value|
        if key =~ /HTTP_(.*)/
          headers[$1] = value
        end
      }
      headers['HOST'] = uri.host if all_opts[:preserve_host]
      headers['X-Forwarded-Host'] = rackreq.host if all_opts[:x_forwarded_host]
 
      session = Net::HTTP.new(uri.host, uri.port)
      session.read_timeout=all_opts[:timeout] if all_opts[:timeout]

      session.use_ssl = (uri.scheme == 'https')
      if uri.scheme == 'https' && all_opts[:verify_ssl]
        session.verify_mode = OpenSSL::SSL::VERIFY_PEER
      else
        # DO NOT DO THIS IN PRODUCTION !!!
        session.verify_mode = OpenSSL::SSL::VERIFY_NONE
      end
      session.start { |http|
{'fraction_non_alphanumeric': 0.1330827067669173, 'fraction_numerical': 0.0030075187969924814, 'mean_word_length': 2.8014285714285716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7556603', 'n_tokens_mistral': 895, 'n_tokens_neox': 861, 'n_words': 190}