<commit_before>#  By default, proxies a URL after checking the EZProxy API to see if
#  it's proxy-able. But you can set the config param precheck_with_api
#  to false, and then this will simply automatically proxy all links
#  from umlaut responses.  That is useful if you have your EZProxy
#  server set to automatically redirect non-proxyable URLs to the original
#  non-proxied version, the API check may not be neccesary. 

# Required parameters:
#   proxy_server: hostname of EZProxy instance (no "http://", just hostname)
#
#   optional params:
#   proxy_password (the ProxyURLPassword  parameter in ezproxy.cfg; must be set
#                   to turn on proxy url api feature ).
#   proxy_url_path: defaults to /proxy_url, the default ezproxy path to call api
#   exclude_hosts: array of hosts to exclude from proxying _even if_ found in
#                  ezproxy config. Each entry can be a string, in which
#                  case it must match host portion of url exactly. Or it can 
#                  be a regexp, which will be tested against entire url.
#                  (supply a string inside // markers. eg '/regexp/' ).
#
#   This service is a link_out_filter service, it must be setup in your
#   services.yml with "task: link_out_filter ".


class Ezproxy < Service
  required_config_params :proxy_server
  
  require 'rexml/document'
  require 'uri'
  require 'net/http'
  require 'cgi'  

  def initialize(config)
    @precheck_with_api = true

    @proxy_login_path = "/login"
    
    super(config)
    
    
    @proxy_url_path ||= "/proxy_url"
    @proxy_url_path = "/" + @proxy_url_path unless @proxy_url_path[0,1] = '/'

    @exclude ||= []
  end

  # This is meant to be called as task:link_out_filter, it doesn't have an
  # implementation for handle, it implements link_out_filter() instead. 
  def handle(request)
     raise "Not implemented."
  end

  # Hook method called by Umlaut. 
  # Returns a proxied url if it should be proxied, or nil if the url
  # can not or does not need to be proxied. 
  def link_out_filter(orig_url, service_type, other_args = {})
    # bad uri? Forget it.
    
    return nil unless valid_url?( orig_url )
    
    # If it's already proxied, leave it alone.
    return nil if already_proxied(orig_url)

    return nil if excluded?(orig_url)

    new_url = nil<commit_msg>forgive trailing/leading whitespace in URLs in EZProxy adapter<commit_after>#  By default, proxies a URL after checking the EZProxy API to see if
#  it's proxy-able. But you can set the config param precheck_with_api
#  to false, and then this will simply automatically proxy all links
#  from umlaut responses.  That is useful if you have your EZProxy
#  server set to automatically redirect non-proxyable URLs to the original
#  non-proxied version, the API check may not be neccesary. 

# Required parameters:
#   proxy_server: hostname of EZProxy instance (no "http://", just hostname)
#
#   optional params:
#   proxy_password (the <PASSWORD>URLPassword  parameter in ezproxy.cfg; must be set
#                   to turn on proxy url api feature ).
#   proxy_url_path: defaults to /proxy_url, the default ezproxy path to call api
#   exclude_hosts: array of hosts to exclude from proxying _even if_ found in
#                  ezproxy config. Each entry can be a string, in which
#                  case it must match host portion of url exactly. Or it can 
#                  be a regexp, which will be tested against entire url.
#                  (supply a string inside // markers. eg '/regexp/' ).
#
#   This service is a link_out_filter service, it must be setup in your
#   services.yml with "task: link_out_filter ".


class Ezproxy < Service
  required_config_params :proxy_server
  
  require 'rexml/document'
  require 'uri'
  require 'net/http'
  require 'cgi'  

  def initialize(config)
    @precheck_with_api = true

    @proxy_login_path = "/login"
    
    super(config)
    
    
    @proxy_url_path ||= "/proxy_url"
    @proxy_url_path = "/" + @proxy_url_path unless @proxy_url_path[0,1] = '/'

    @exclude ||= []
  end

  # This is meant to be called as task:link_out_filter, it doesn't have an
  # implementation for handle, it implements link_out_filter() instead. 
  def handle(request)
     raise "Not implemented."
  end

  # Hook method called by Umlaut. 
  # Returns a proxied url if it should be proxied, or nil if the url
  # can not or does not need to be proxied. 
  def link_out_filter(orig_url, service_type, other_args = {})
    # remove trailing or leading whitespace from url, it makes it
    # an illegal URL anyway, but maybe we can rescue it? Marc 856's
    # sometimes have accidental trailing whitespace. 
    orig_url = orig_url.strip
    
    # bad uri? Forget it.    
    return nil unless valid_url?( orig_url )
    
    # If it's already proxied, leave it alone.
    return nil if already_proxied(orig_url)

    return nil if excluded?(orig_url)

    new_url = nil
{'fraction_non_alphanumeric': 0.07082324455205811, 'fraction_numerical': 0.0014124293785310734, 'mean_word_length': 2.931007137192704, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1662296', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1463, 'n_words': 601}