File: extensions.rb

package info (click to toggle)
ruby-httpx 1.7.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,816 kB
  • sloc: ruby: 12,209; makefile: 4
file content (45 lines) | stat: -rw-r--r-- 942 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

require "uri"

module HTTPX
  module ArrayExtensions
    module Intersect
      refine Array do
        # Ruby 3.1 backport
        def intersect?(arr)
          if size < arr.size
            smaller = self
          else
            smaller, arr = arr, self
          end
          (arr & smaller).size > 0
        end
      end unless Array.method_defined?(:intersect?)
    end
  end

  module URIExtensions
    # uri 0.11 backport, ships with ruby 3.1
    refine URI::Generic do

      def non_ascii_hostname
        @non_ascii_hostname
      end

      def non_ascii_hostname=(hostname)
        @non_ascii_hostname = hostname
      end

      def authority
        return host if port == default_port

        "#{host}:#{port}"
      end unless URI::HTTP.method_defined?(:authority)

      def origin
        "#{scheme}://#{authority}"
      end unless URI::HTTP.method_defined?(:origin)
    end
  end
end