D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
OpenURI
/
OpenRead
/
Filename :
open-i.ri
back
Copy
U:RDoc::AnyMethod[iI" open:ETI"OpenURI::OpenRead#open;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"GOpenURI::OpenRead#open provides `open' for URI::HTTP and URI::FTP.;To:RDoc::Markup::BlankLine o; ; [I":OpenURI::OpenRead#open takes optional 3 arguments as:;T@o:RDoc::Markup::Verbatim; [I"GOpenURI::OpenRead#open([mode [, perm]] [, options]) [{|io| ... }] ;T:@format0o; ; [I"MOpenURI::OpenRead#open returns an IO-like object if block is not given. ;TI"JOtherwise it yields the IO object and return the value of the block. ;TI"2The IO object is extended with OpenURI::Meta.;T@o; ; [I"3+mode+ and +perm+ are the same as Kernel#open.;T@o; ; [I"NHowever, +mode+ must be read mode because OpenURI::OpenRead#open doesn't ;TI"support write mode (yet). ;TI"LAlso +perm+ is ignored because it is meaningful only for file creation.;T@o; ; [I"+options+ must be a hash.;T@o; ; [I"MEach option with a string key specifies an extra header field for HTTP. ;TI"4I.e., it is ignored for FTP without HTTP proxy.;T@o; ; [I"@The hash may include other options, where keys are symbols:;T@o:RDoc::Markup::List: @type: LABEL:@items[o:RDoc::Markup::ListItem:@label[I":proxy;T; [o; ; [I"Synopsis:;To;; [ I",:proxy => "http://proxy.foo.com:8000/" ;TI"7:proxy => URI.parse("http://proxy.foo.com:8000/") ;TI":proxy => true ;TI":proxy => false ;TI":proxy => nil ;T; 0o; ; [I"EIf :proxy option is specified, the value should be String, URI, ;TI"boolean or nil.;T@o; ; [I"=When String or URI is given, it is treated as proxy URI.;T@o; ; [I"?When true is given or the option itself is not specified, ;TI"6environment variable `scheme_proxy' is examined. ;TI"6`scheme' is replaced by `http', `https' or `ftp'.;T@o; ; [I"KWhen false or nil is given, the environment variables are ignored and ;TI"2connection will be made to a server directly.;T@o;;[I"%:proxy_http_basic_authentication;T; [ o; ; [I"Synopsis:;To;; [ I"):proxy_http_basic_authentication => ;TI"F ["http://proxy.foo.com:8000/", "proxy-user", "proxy-password"] ;TI"):proxy_http_basic_authentication => ;TI"1 [URI.parse("http://proxy.foo.com:8000/"), ;TI"( "proxy-user", "proxy-password"] ;T; 0o; ; [ I"HIf :proxy option is specified, the value should be an Array with 3 ;TI"Melements. It should contain a proxy URI, a proxy user name and a proxy ;TI"Lpassword. The proxy URI should be a String, an URI or nil. The proxy ;TI"/user name and password should be a String.;T@o; ; [I"DIf nil is given for the proxy URI, this option is just ignored.;T@o; ; [I"BIf :proxy and :proxy_http_basic_authentication is specified, ;TI"ArgumentError is raised.;T@o;;[I":http_basic_authentication;T; [ o; ; [I"Synopsis:;To;; [I"2:http_basic_authentication=>[user, password] ;T; 0o; ; [ I"1If :http_basic_authentication is specified, ;TI"<the value should be an array which contains 2 strings: ;TI"username and password. ;TI"BIt is used for HTTP Basic authentication defined by RFC 2617.;T@o;;[I":content_length_proc;T; [ o; ; [I"Synopsis:;To;; [I"<:content_length_proc => lambda {|content_length| ... } ;T; 0o; ; [I"MIf :content_length_proc option is specified, the option value procedure ;TI"2is called before actual transfer is started. ;TI"FIt takes one argument, which is expected content length in bytes.;T@o; ; [I"EIf two or more transfers are performed by HTTP redirection, the ;TI"9procedure is called only once for the last transfer.;T@o; ; [I"KWhen expected content length is unknown, the procedure is called with ;TI"Lnil. This happens when the HTTP response has no Content-Length header.;T@o;;[I":progress_proc;T; [o; ; [I"Synopsis:;To;; [I"+:progress_proc => lambda {|size| ...} ;T; 0o; ; [I"HIf :progress_proc option is specified, the proc is called with one ;TI"Hargument each time when `open' gets content fragment from network. ;TI"FThe argument +size+ is the accumulated transferred size in bytes.;T@o; ; [I"HIf two or more transfer is done by HTTP redirection, the procedure ;TI",is called only one for a last transfer.;T@o; ; [I"I:progress_proc and :content_length_proc are intended to be used for ;TI"progress bar. ;TI"JFor example, it can be implemented as follows using Ruby/ProgressBar.;T@o;; [I"pbar = nil ;TI"open("http://...", ;TI"+ :content_length_proc => lambda {|t| ;TI" if t && 0 < t ;TI", pbar = ProgressBar.new("...", t) ;TI"# pbar.file_transfer_mode ;TI" end ;TI" }, ;TI"% :progress_proc => lambda {|s| ;TI" pbar.set s if pbar ;TI" }) {|f| ... } ;T; 0o;;[I":read_timeout;T; [ o; ; [I"Synopsis:;To;; [I"):read_timeout=>nil (no timeout) ;TI"(:read_timeout=>10 (10 second) ;T; 0o; ; [I"K:read_timeout option specifies a timeout of read for http connections.;T@o;;[I":open_timeout;T; [ o; ; [I"Synopsis:;To;; [I"):open_timeout=>nil (no timeout) ;TI"(:open_timeout=>10 (10 second) ;T; 0o; ; [I"K:open_timeout option specifies a timeout of open for http connections.;T@o;;[I":ssl_ca_cert;T; [ o; ; [I"Synopsis:;To;; [I"5:ssl_ca_cert=>filename or an Array of filenames ;T; 0o; ; [I"=:ssl_ca_cert is used to specify CA certificate for SSL. ;TI"7If it is given, default certificates are not used.;T@o;;[I":ssl_verify_mode;T; [ o; ; [I"Synopsis:;To;; [I":ssl_verify_mode=>mode ;T; 0o; ; [I"=:ssl_verify_mode is used to specify openssl verify mode.;T@o;;[I":ssl_min_version;T; [ o; ; [I"Synopsis:;To;; [I":ssl_min_version=>:TLS1_2 ;T; 0o; ; [I"L:ssl_min_version option specifies the minimum allowed SSL/TLS protocol ;TI">version. See also OpenSSL::SSL::SSLContext#min_version=.;T@o;;[I":ssl_max_version;T; [ o; ; [I"Synopsis:;To;; [I":ssl_max_version=>:TLS1_2 ;T; 0o; ; [I"L:ssl_max_version option specifies the maximum allowed SSL/TLS protocol ;TI">version. See also OpenSSL::SSL::SSLContext#max_version=.;T@o;;[I":ftp_active_mode;T; [ o; ; [I"Synopsis:;To;; [I":ftp_active_mode=>bool ;T; 0o; ; [I"H<tt>:ftp_active_mode => true</tt> is used to make ftp active mode. ;TI",Ruby 1.9 uses passive mode by default. ;TI"?Note that the active mode is default in Ruby 1.8 or prior.;T@o;;[I":redirect;T; [o; ; [I"Synopsis:;To;; [I":redirect=>bool ;T; 0o; ; [I"M+:redirect+ is true by default. <tt>:redirect => false</tt> is used to ;TI" disable all HTTP redirects.;T@o; ; [I"<OpenURI::HTTPRedirect exception raised on redirection. ;TI"HUsing +true+ also means that redirections between http and ftp are ;TI"permitted.;T@o;;[I":max_redirects;T; [ o; ; [I"Synopsis:;To;; [I":max_redirects=>int ;T; 0o; ; [I"RNumber of HTTP redirects allowed before OpenURI::TooManyRedirects is raised. ;TI"The default is 64.;T@o;;[I":request_specific_fields;T; [o; ; [I"Synopsis:;To;; [I"$:request_specific_fields => {} ;TI"4:request_specific_fields => lambda {|url| ...} ;T; 0o; ; [I"Q:request_specific_fields option allows specifying custom header fields that ;TI"Oare sent with the HTTP request. It can be passed as a Hash or a Proc that ;TI"Hgets evaluated on each request and returns a Hash of header fields.;T@o; ; [I"JIf a Hash is provided, it specifies the headers only for the initial ;TI"=request and these headers will not be sent on redirects.;T@o; ; [ I"KIf a Proc is provided, it will be executed for each request including ;TI"Predirects, allowing dynamic header customization based on the request URL. ;TI"OIt is important that the Proc returns a Hash. And this Hash specifies the ;TI")headers to be sent with the request.;T@o; ; [I"For Example with Hash;To;; [I"URI.open("http://...", ;TI"V request_specific_fields: {"Authorization" => "token dummy"}) {|f| ... } ;T; 0o; ; [I"For Example with Proc:;To;; [ I"URI.open("http://...", ;TI"6 request_specific_fields: lambda { |uri| ;TI"- if uri.host == "example.com" ;TI"5 {"Authorization" => "token dummy"} ;TI" else ;TI" {} ;TI" end ;TI" }) {|f| ... };T; 0: @fileI"lib/open-uri.rb;T:0@omit_headings_from_table_of_contents_below000[ I"(*rest, &block);T@_FI" OpenRead;TcRDoc::NormalModule00