Skip to content

Commit fff0145

Browse files
committed
parser: use URI#open instead of URI.open
Signed-off-by: Shizuo Fujita <[email protected]>
1 parent 1fa4f94 commit fff0145

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/fluent/config/parser.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,24 @@ def process_include(attrs, elems, uri, allow_include = true)
9292
else
9393
basepath = '/'
9494
fname = path
95-
require 'open-uri'
96-
URI.open(uri) {|f|
95+
parser_proc = ->(f) {
9796
Parser.new(basepath, f.each_line, fname).parse!(allow_include, nil, attrs, elems)
9897
}
98+
99+
case u.scheme
100+
when 'http', 'https', 'ftp'
101+
# URI#open can be able to handle URIs for http, https and ftp.
102+
require 'open-uri'
103+
u.open { |f| parser_proc.call(f) }
104+
else
105+
# For other, it use File.open to handle the file.
106+
# Mainly this case will be used when it handles Windows files.
107+
# 'c:/path/to/file' will be passed as URI, 'uri' and 'u.path' will be:
108+
# - uri is 'c:/path/to/file'
109+
# - u.path is '/path/to/file' and u.scheme is 'c'
110+
# Therefore, the condition of the if statement above is not met and it is handled here.
111+
File.open(u.path) { |f| parser_proc.call(f) }
112+
end
99113
end
100114

101115
rescue SystemCallError => e
@@ -104,4 +118,3 @@ def process_include(attrs, elems, uri, allow_include = true)
104118
end
105119
end
106120
end
107-

0 commit comments

Comments
 (0)