summaryrefslogtreecommitdiff
path: root/lib/net
AgeCommit message (Collapse)Author
2018-12-04Use delete_prefix instead of `sub(/\Afixed-pattern/, '')`kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-05Fix up r65505 [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-02lib/*: Prefer require_relative over require.marcandre
[#15206] [Fix GH-1976] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-21lib/net/http.rb: [DOC] fix typosstomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20Add negotiated SSL protocol and cipher to Net::HTTP debug outputnaruse
From: Bart de Water <bartdewater@gmail.com> https://github.com/ruby/ruby/pull/1877 [Feature #15009] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20Improve doc of multipart/form-data [Bug #15019]aycabta
* lib/net/http.rb: Documentation for Net::HTTP claims that multipart/form-data is not supported, but Net::HTTPHeader#set_form supports it since 1.9.3. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65230 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-19net/http: Improve net/http header error message.marcandre
Patch by Matt Larraz. [Fix GH-1849]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-03Use unpack1 instead of unpack and `[0]`kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64622 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-08net/http, net/ftp: fix session resumption with TLS 1.3rhe
When TLS 1.3 is in use, the session ticket may not have been sent yet even though a handshake has finished. Also, the ticket could change if multiple session ticket messages are sent by the server. Use SSLContext#session_new_cb instead of calling SSLSocket#session immediately after a handshake. This way also works with earlier protocol versions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-14Get rid of warnings of test/specusa
* lib/net/http/exceptions.rb: revert a part of r63590. to deprecate Net::ProtoServerError seems to be wrong. see [ruby-core:87488] [Feature#14688] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-08write_timeout doc upates [skip ci]naruse
From: MSP-Greg <MSP-Greg@users.noreply.github.com> fix https://github.com/ruby/ruby/pull/1885 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-07Fix typos [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63600 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-06Use `Net::HTTPClientException` instead of `Net::HTTPServerException`naruse
`Net::HTTPServerException` has been deprecated since r63590. [Bug #14688] And `net/http/responses.rb` uses the deprecated constant, so Ruby warns of the deprecation. Example: ```bash $ ruby -r net/http -e '' /home/pocke/.rbenv/versions/trunk/lib/ruby/2.6.0/net/http/responses.rb:22: warning: constant Net::HTTPServerException is deprecated ``` This change suppresses the warning. From: Masataka Pocke Kuwabara <kuwabara@pocke.me> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-06Add Net::HTTPClientException [Bug #14688]naruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-06fix r63587naruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-06fix r63587 with temporal patch to pass the tests. please re-fix it.ko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-06Introduce write_timeout to Net::HTTP [Feature #13396]naruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63587 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-11net/imap: Fix ArgumentError in send_string_datashugo
Thanks to ShockwaveNN (Pavel Lobashov) for reporting the bug. [ruby-core:86990] [Bug #14750] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-22net/imap: set SO_KEEPALIVE on TCP socketsnormal
Otherwise connections (commonly on IDLE, but it could be any command) may never receive notifications of link errors. [ruby-core:86628] [Feature #14703] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-08Raise ArgumentError if host component is nilnaruse
From: oss92 <mohamed.o.alnagdy@gmail.com> fix https://github.com/ruby/ruby/pull/1278 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62698 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-30net/http: fix documentation for HTTP connection reusenormal
Thanks to Paul Kuruvilla <rohitpaulk@gmail.com> for the patch * lib/net/http.rb: fix documentation for HTTP connection reuse [ruby-core:84815] [Bug #14349] From: Paul Kuruvilla <rohitpaulk@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62113 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-30net/pop: make modified strings mutablenormal
Thanks to Michael Zimmerman for the bug report * lib/net/pop.rb: make modified strings mutable [ruby-core:85210] [Bug #14416] * test/net/pop/test_pop.rb: new test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-19Fix warningkazu
``lib/net/protocol.rb:214: warning: `*' interpreted as argument prefix`` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-14net/http: use writev for HTTP chunked request bodiesnormal
This reduces both user and system CPU time for large uploads with dynamically-generated request bodies. user system total real before: 0.393334 1.580000 1.973334 ( 1.971066) after: 0.223334 0.976666 1.200000 ( 1.198514) ------ require 'socket' require 'net/http' require 'benchmark' nr = 1024 * 1024 * 1024 s = TCPServer.new('127.0.0.1', 0) addr = s.addr at_exit { Process.waitall } fork do c = s.accept # not exactly accurate but fast IO.copy_stream(c, '/dev/null', nr + 500000) begin buf = c.readpartial(16384) tmp = '' until buf.end_with?(-"0\r\n\r\n") buf << c.readpartial(16384, tmp) end rescue EOFError end c.write "HTTP/1.1 201 Created\r\nConnection:close\r\n\r\n" c.close end r, w = IO.pipe fork do r.close IO.copy_stream('/dev/zero', w, nr) w.close end w.close Net::HTTP.start(addr[3], addr[1]) do |http| put = Net::HTTP::Put.new('/dev0/foo') put['Content-Type'] = 'application/content-type' put['Transfer-Encoding'] = 'chunked' put.body_stream = r puts(Benchmark.measure { http.request(put) }) end ------ * lib/net/http/generic_request.rb (write): use multi-arg write * lib/net/protocol.rb (write): support multi-arg (write0): ditto [ruby-core:84845] [Feature #14339] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61812 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-12Add `103 Early Hints` to `Net::HTTP::STATUS_CODES` [ci skip]kazu
Update by `ruby lib/net/http/status.rb | sponge lib/net/http/status.rb` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08net/http: clear compressed chunk after decompressionnormal
We no longer need the compressed data once the inflate block is called; so clear it ASAP to reduce memory overhead. This is a small chunk, so it only saves a few hundred kilobytes with the script below. before: RssAnon: 5976 kB after: RssAnon: 5564 kB ------ require 'net/http' require 'zlib' response_gz = ARGV.shift or abort "#$0 TEMPORARY_FILE" # pre-create response since compressing is slower than decompressing unless File.readable?(response_gz) nr = 16384 * 2 buf = ((0..255).map(&:chr).join * 128) File.open(response_gz, 'wb') do |fp| gzip = Zlib::GzipWriter.new(fp) nr.times { gzip.write(buf) } gzip.close end buf.clear end response_gz = File.open(response_gz) s = TCPServer.new('127.0.0.1', 0) pid = fork do c = s.accept c.readpartial(16384).clear c.write("HTTP/1.1 200 OK\r\n" \ "Content-Length: #{response_gz.stat.size}\r\n" \ "Content-Encoding: gzip\r\n" \ "Accept-Ranges: bytes\r\n" \ "\r\n") IO.copy_stream(response_gz, c) c.close end addr = s.addr Net::HTTP.start(addr[3], addr[1]) do |http| http.request_get(-'/') do |res| res.read_body(&:clear) end end puts File.readlines(-'/proc/self/status').grep(/RssAnon/)[0] Process.waitpid2(pid) ------ * lib/net/http/response.rb (inflate_adapter): clear compressed_chunk git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61684 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08net/protocol: read directly into rbuf if it's emptynormal
There's no need to allocate a temporary string when @rbuf is empty, we can use it as the read_nonblock destination buffer to save both allocation overhead and avoid a later memcpy. This results in a halving user CPU time and tiny memory reduction with the script below: user system total real before 0.603333 0.539999 1.143332 ( 1.143347) RssAnon: 5624 kB after 0.283334 0.560000 0.843334 ( 0.846072) RssAnon: 5592 kB ------ require 'net/http' require 'benchmark' s = TCPServer.new('127.0.0.1', 0) len = 1024 * 1024 * 1024 * 2 pid = fork do c = s.accept c.readpartial(16384).clear c.send("HTTP/1.0 200 OK\r\nContent-Length: #{len}\r\n\r\n", Socket::MSG_MORE) IO.copy_stream('/dev/zero', c, len) c.close end addr = s.addr Net::HTTP.start(addr[3], addr[1]) do |http| http.request_get('/') do |res| puts(Benchmark.measure { res.read_body(&:clear) }) end end puts File.readlines("/proc/self/status").grep(/RssAnon/)[0] Process.waitpid2(pid) ------ * lib/net/protocol.rb (rbuf_fill): avoid allocation if rbuf is empty [ruby-core:84678] [Feature #14326] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08net/protocol: use binary string buffersnormal
Not an encoding expert, but this seems necessary for the next change. All of the IO#read, IO#read_nonblock and related methods will return a binary string when given a length argument; so anything appended to these buffers via << will be binary. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-06Revert "net/protocol: use binary string buffers"normal
Oops, not ready, yet (will work on this tomorrow :x). This reverts commit r61638 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-06net/ftp: fix FrozenError in BufferedSocketnormal
I noticed this bug while working on something else with RUBYOPT=-d on, existing test cases all passed with it. Note: I use String.new because it is the local style, here, I prefer +'' (or ''.b, for a future commit) * lib/net/ftp.rb (BufferedSocket#read): use String.new * test/net/ftp/test_buffered_socket.rb (test_read_nil): new test [ruby-core:84675] [Bug #14323] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-06net/protocol: use binary string buffersnormal
Not an encoding expert, but this seems necessary for the next change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61638 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-06Update Status Codekazu
see https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-06Add 103 Early Hintskazu
see https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-06Specify frozen_string_literal: truekazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05net/protocol: optimize large read casenormal
There are several places where rbuf_consume is called with @rbuf.size as its length arg; simplify that case by avoiding the slow String#slice! operation in favor of a lightweight replacement. The following script exhibits reduced memory usage and runtimes using the time(1) command: 2.9s => 2.6s 70MB => 12 MB --------- require 'net/http' require 'digest/md5' Thread.abort_on_exception = true s = TCPServer.new('127.0.0.1', 0) len = 1024 * 1024 * 1024 th = Thread.new do c = s.accept c.readpartial(16384) c.write("HTTP/1.0 200 OK\r\nContent-Length: #{len}\r\n\r\n") IO.copy_stream('/dev/zero', c, len) c.close end addr = s.addr Net::HTTP.start(addr[3], addr[1]) do |http| http.request_get('/') do |res| dig = Digest::MD5.new res.read_body { |buf| dig.update(buf) # String#clear is important to reduce malloc overhead, # but most Ruby programmers don't do this :< buf.clear } puts dig.hexdigest end end ---------- * lib/net/protocol (rbuf_consume): optimize for @rbuf.size == len [Feature #14268] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-20raise error if value contains CR/LF in iniheader of initialize_http_headernaruse
like r59693, initialize_http_header also should raise error. [Bug #14208] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-14Fix a command injection vulnerability in Net::FTP.nagachika
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12Add uplevel keyword to Kernel#warn and use itshyouhei
If uplevel keyword is given, the warning message is prepended with caller file and line information and the string "warning: ". The use of the uplevel keyword makes Kernel#warn format output similar to how rb_warn formats output. This patch modifies net/ftp and net/imap to use Kernel#warn instead of $stderr.puts or $stderr.printf, since they are used for printing warnings. This makes lib/cgi/core and tempfile use $stderr.puts instead of warn for debug logging, since they are used for debug printing and not for warning. This does not modify bundler, rubygems, or rdoc, as those are maintained outside of ruby and probably wish to remain backwards compatible with older ruby versions. rb_warn_m code is originally from nobu, but I've changed it so that it only includes the path and lineno from uplevel (not the method), and also prepends the string "warning: ", to make it more similar to rb_warn. From: Jeremy Evans code@jeremyevans.net Signed-off-by: Urabe Shyouhei shyouhei@ruby-lang.org git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-07http.rb: improve docsstomar
* lib/net/http.rb: [DOC] fix typos and grammar git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60710 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26Host header should add branckets to IPv6 address [Bug #12642]naruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-24net/http: use require_relative to reduce syscallsnormal
require_relative speeds up loading of files by reducing path lookups. On a clean install with RubyGems-enabled, "ruby -rnet/http -e exit" shows a reduction in failed open(2) syscalls from 410 to 350 (x86-64 GNU/Linux). I could not measure a time difference on my Linux-based machines, however this should be noticeable to users of other kernels with worse syscall and VFS performance than Linux. Further use of require_relative will reduce lookups in other places. * lib/net/http.rb: use require_relative [ruby-core:78285] [Feature #12973] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22Fixed misspelling words.hsbt
These are detected by https://github.com/client9/misspell git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21Introduce Net::HTTP#min_version/max_version [Feature #9450]naruse
Set SSL minimum/maximum version. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21Use caller with length to reduce unused stringskazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-17Fix warning: assigned but unused variablekazu
[Bug #14020][ruby-core:83313] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-28Net::HTTP.new: Support no_proxy parameter [Feature #11195]naruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60054 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-27Fix exception class [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-26Make retries for Net::HTTP configurable [Feature #10674]naruse
by stereobooster fix https://github.com/ruby/ruby/pull/1654 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-25HTTPHeader#add_field should allow binary [Bug #13926]naruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-20Prefer adapting specs to complicating library codeeregon
* lib/net/ftp.rb (Net::FTP#initialize): simplify as per the original intent. * spec/ruby/library/net/ftp/initialize_spec.rb: adapt specs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e