You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: url_helper.rb
    path of file: ./repos/discourse/lib
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

class UrlHelper
  MAX_URL_LENGTH = 2_000

  # At the moment this handles invalid URLs that browser address bar accepts
  # where second # is not encoded
  #
  # Longer term we can add support of simpleidn and encode unicode domains
  def self.relaxed_parse(url)
    url, fragment = url.split("#", 2)
    uri = URI.parse(url)
    if uri
      # Addressable::URI::CharacterClasses::UNRESERVED is used here because without it
      # the # in the fragment is not encoded
      fragment =
        Addr
    
  def self.cook_url(url, secure: false, local: nil)
    is_secure = SiteSetting.secure_uploads && secure
    local = is_local(url) if local.nil?
    return url if !local

    url = is_secure ? secure_proxy_without_cdn(url) : absolute_without_cdn(url)

    # we always want secure uploads to come from
    # Discourse.base_url_no_prefix/secure-uploads
    # to avoid asset_host mixups
    return schemaless(url) if is_secure

    # PERF: avoid parsing url except for extreme conditions
    # this is a hot path used on home page
    filename = url
    if url.include?("?")
      uri = URI.parse(url)
      filename = File.basename(uri.path)
    end