open-uri 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78f03a56856bfc2aa1dbdd08478f6bda3ea2c29f83d7cd99ef762f5c0b52e067
4
- data.tar.gz: cbd9c8771d3eb265509ad998d1331098f1866000e07ab8cfaa3dfaac4f31a360
3
+ metadata.gz: d13353141f32e54cbb98e25fe19197d3ad8224d3c661fba933442db5b18b3b2e
4
+ data.tar.gz: ef41b498379d50506d963d85993281d29b9c67723ac791bfeb6221a395141c9d
5
5
  SHA512:
6
- metadata.gz: 23431550f621fade4ae9fa17ab13212dfc4a4d401d44e0b483e0315f223eb237610fb761acdc36c2eba70259aed5f11fc1fec748cdc75b8390dd2873a00f3ff0
7
- data.tar.gz: dbb275774fe23edfaf364819ebabe871378831f3fa758a25aa9641040887cd878945b84d2a42b32d0436d0ecfcf35e2358be143028b25cce0bcbb57b5fa73176
6
+ metadata.gz: e520fd4b3d3ede380bf840470bf28a2d529f7bc2658a6e8645436b53c0dd2808cefd899e5eff73391a54974760decb29511795c50348a29d02b598e23fed2433
7
+ data.tar.gz: e6bff48cd004d12658c238ed6a2979be0a4a12ef6c670e99cb36f6cb6cb88359ff1ca0b4968c5d428185c02a7c055af3290deeacc4d9bb42c2ad20249dc5f3f7
@@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without
4
4
  modification, are permitted provided that the following conditions
5
5
  are met:
6
6
  1. Redistributions of source code must retain the above copyright
7
- notice, this list of conditions and the following disclaimer.
7
+ notice, this list of conditions and the following disclaimer.
8
8
  2. Redistributions in binary form must reproduce the above copyright
9
- notice, this list of conditions and the following disclaimer in the
10
- documentation and/or other materials provided with the distribution.
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
11
 
12
12
  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
13
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
data/COPYING ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a. place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b. use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c. give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d. make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a. distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b. accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c. give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d. make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
data/lib/open-uri.rb CHANGED
@@ -91,7 +91,7 @@ end
91
91
 
92
92
  module OpenURI
93
93
 
94
- VERSION = "0.4.1"
94
+ VERSION = "0.5.0"
95
95
 
96
96
  Options = {
97
97
  :proxy => true,
@@ -109,6 +109,7 @@ module OpenURI
109
109
  :redirect => true,
110
110
  :encoding => nil,
111
111
  :max_redirects => 64,
112
+ :request_specific_fields => nil,
112
113
  }
113
114
 
114
115
  def OpenURI.check_options(options) # :nodoc:
@@ -148,7 +149,11 @@ module OpenURI
148
149
  end
149
150
  encoding = Encoding.find(options[:encoding])
150
151
  end
151
-
152
+ if options.has_key? :request_specific_fields
153
+ if !(options[:request_specific_fields].is_a?(Hash) || options[:request_specific_fields].is_a?(Proc))
154
+ raise ArgumentError, "Invalid request_specific_fields option: #{options[:request_specific_fields].inspect}"
155
+ end
156
+ end
152
157
  unless mode == nil ||
153
158
  mode == 'r' || mode == 'rb' ||
154
159
  mode == File::RDONLY
@@ -212,12 +217,20 @@ module OpenURI
212
217
  end
213
218
 
214
219
  uri_set = {}
215
- max_redirects = options[:max_redirects]
220
+ max_redirects = options[:max_redirects] || Options.fetch(:max_redirects)
216
221
  buf = nil
217
222
  while true
223
+ request_specific_fields = {}
224
+ if options.has_key? :request_specific_fields
225
+ request_specific_fields = if options[:request_specific_fields].is_a?(Hash)
226
+ options[:request_specific_fields]
227
+ else options[:request_specific_fields].is_a?(Proc)
228
+ options[:request_specific_fields].call(uri)
229
+ end
230
+ end
218
231
  redirect = catch(:open_uri_redirect) {
219
232
  buf = Buffer.new
220
- uri.buffer_open(buf, find_proxy.call(uri), options)
233
+ uri.buffer_open(buf, find_proxy.call(uri), options.merge(request_specific_fields))
221
234
  nil
222
235
  }
223
236
  if redirect
@@ -237,6 +250,10 @@ module OpenURI
237
250
  options = options.dup
238
251
  options.delete :http_basic_authentication
239
252
  end
253
+ if options.include?(:request_specific_fields) && options[:request_specific_fields].is_a?(Hash)
254
+ # Send request specific headers only for the initial request.
255
+ options.delete :request_specific_fields
256
+ end
240
257
  uri = redirect
241
258
  raise "HTTP redirection loop: #{uri}" if uri_set.include? uri.to_s
242
259
  uri_set[uri.to_s] = true
@@ -746,6 +763,44 @@ module OpenURI
746
763
  # Using +true+ also means that redirections between http and ftp are
747
764
  # permitted.
748
765
  #
766
+ # [:max_redirects]
767
+ # Synopsis:
768
+ # :max_redirects=>int
769
+ #
770
+ # Number of HTTP redirects allowed before OpenURI::TooManyRedirects is raised.
771
+ # The default is 64.
772
+ #
773
+ # [:request_specific_fields]
774
+ # Synopsis:
775
+ # :request_specific_fields => {}
776
+ # :request_specific_fields => lambda {|url| ...}
777
+ #
778
+ # :request_specific_fields option allows specifying custom header fields that
779
+ # are sent with the HTTP request. It can be passed as a Hash or a Proc that
780
+ # gets evaluated on each request and returns a Hash of header fields.
781
+ #
782
+ # If a Hash is provided, it specifies the headers only for the initial
783
+ # request and these headers will not be sent on redirects.
784
+ #
785
+ # If a Proc is provided, it will be executed for each request including
786
+ # redirects, allowing dynamic header customization based on the request URL.
787
+ # It is important that the Proc returns a Hash. And this Hash specifies the
788
+ # headers to be sent with the request.
789
+ #
790
+ # For Example with Hash
791
+ # URI.open("http://...",
792
+ # request_specific_fields: {"Authorization" => "token dummy"}) {|f| ... }
793
+ #
794
+ # For Example with Proc:
795
+ # URI.open("http://...",
796
+ # request_specific_fields: lambda { |uri|
797
+ # if uri.host == "example.com"
798
+ # {"Authorization" => "token dummy"}
799
+ # else
800
+ # {}
801
+ # end
802
+ # }) {|f| ... }
803
+ #
749
804
  def open(*rest, &block)
750
805
  OpenURI.open_uri(self, *rest, &block)
751
806
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open-uri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanaka Akira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-07 00:00:00.000000000 Z
11
+ date: 2024-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uri
@@ -59,7 +59,8 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - LICENSE.txt
62
+ - BSDL
63
+ - COPYING
63
64
  - README.md
64
65
  - lib/open-uri.rb
65
66
  homepage: https://github.com/ruby/open-uri
@@ -69,7 +70,7 @@ licenses:
69
70
  metadata:
70
71
  homepage_uri: https://github.com/ruby/open-uri
71
72
  source_code_uri: https://github.com/ruby/open-uri
72
- post_install_message:
73
+ post_install_message:
73
74
  rdoc_options: []
74
75
  require_paths:
75
76
  - lib
@@ -84,8 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
85
  - !ruby/object:Gem::Version
85
86
  version: '0'
86
87
  requirements: []
87
- rubygems_version: 3.5.0.dev
88
- signing_key:
88
+ rubygems_version: 3.5.11
89
+ signing_key:
89
90
  specification_version: 4
90
91
  summary: An easy-to-use wrapper for Net::HTTP, Net::HTTPS and Net::FTP.
91
92
  test_files: []