Граф коммитов

296 Коммитов

Автор SHA1 Сообщение Дата
Tanaka Akira 50d85436f8 WEBrick::HTTPResponse create tempfile if required.
WEBrick::HTTPProxyServer implementes HTTP proxy using
WEBrick and Net::HTTP.
WEBrick accepts HTTP/1.0 clients and
Net::HTTP uses always HTTP/1.1.

However HTTP/1.1 supports chunked transfer coding HTTP/1.0 doesn't.

Chunked transfer coding doesn't require that
content-length before the content is sent.
But non-chunked transfer coding require content-length before
the content is sent.

So, when HTTP/1.0 clients connects WEBrick::HTTPProxyServer and
origin server returns chunked response,
WEBrick::HTTPProxyServer needs to store whole content to
know the length of it.

This patch do it using tempfile.
2019-07-11 09:18:41 +09:00
Rob c6229e7c69 Adds WebAssembly MIME type 2019-06-24 10:11:56 +09:00
Nobuyoshi Nakada 11a60f9bdb Remove extraneous spaces at the end of status line
Remove extraneous spaces after the status code that is
non-compliant with RFC, i.e `HTTP 200 OK `, to unnecessary
confusion for WEBrick users, by a risk that WEBrick instances in
the wild will have server responses flagged as suspicious or
malicious due to a similar bug in [Cobalt Strike
misconfiguration].

Reported by Matt Tennis <mtennis@paloaltonetworks.com>

[Cobalt Strike misconfiguration]: https://blog.fox-it.com/2019/02/26/identifying-cobalt-strike-team-servers-in-the-wild/
2019-06-24 10:11:47 +09:00
Hiroshi SHIBATA efda52ba62
Use cgit instead of svn. 2019-05-07 23:31:03 +09:00
normal 4038d0137f webrick: add the ability to override res, req creation
So that a customized HTTPServer subclass can use it's own
Request/Response classes.

To apply the override, make a subclass of WEBrick::HTTPServer
and override the
`create_request_and_response(with_webrick_config)` method. The
method should return an Array of [request, response].

To check whether the Server supports this method (i.e. when
using older versions of WEBrick when needing this
functionality), you can ask the server if it responds to the
method

    server.respond_to?(:create_request_and_response)

This is backportable.

[ruby-core:69604] [Feature #11266]

From: Julik Tarkhanov <me@julik.nl>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-19 11:08:05 +00:00
normal a063f71a7c webrick: fix tests on Debian sid/unstable with OpenSSL 1.1.1a
OpenSSL complains abour our keys being small and weak :<
Make them big and strong with 2048-bit RSA keys and SHA256 digests

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66152 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 04:51:08 +00:00
mame 7a635a7d12 lib/webrick: explicitly convert header values to a string
The values of @header are expected to be all strings;
WEBrick::HTTPResponse::[]=(key, val) explicitly converts the second
argument to a string and assigns it to @header hash.
However, there were some points in WEBrick internal code that assigns
non-String to @header.  This change fixes the issues.

The values are checked by `header_value =~ /\r\n/` in check_header.
The type confusion caused conflict with removal of `Object#=~`
[Feature #15231].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26 05:29:45 +00:00
marcandre b9d42af0f2 lib/*: Prefer require_relative over require, remove explicit extension
[#15206] [Fix GH-1976]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-02 17:52:43 +00:00
marcandre e859e668d2 lib/*: Prefer require_relative over require.
[#15206] [Fix GH-1976]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-02 17:52:33 +00:00
stomar ef0615b6ef default gems: add missing comment in gemspec
* lib/csv/csv.gemspec: [DOC] add comment for require fallback
  in Ruby repository.

* lib/logger.gemspec: ditto.
* lib/prime.gemspec: ditto.
* lib/rexml/rexml.gemspec: ditto.
* lib/rss/rss.gemspec: ditto.
* lib/webrick/webrick.gemspec: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12 19:58:11 +00:00
normal 1aef602d5a webrick: raise EOFError in parse when read line is nil
[Bug #15146]

From: Justin Li <git@justinli.net>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-24 07:48:33 +00:00
normal ab7e34e4db webrick/httpauth/htgroup.rb (flush): avoid unnecessary unlink
Based on patch by akr [ruby-core:88477], use Tempfile.create
to avoid unnecessary unlink call.  Unlike akr's original patch,
this does not change the return value of flush.

Thanks-to: Tanaka Akira <akr@fsij.org>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-14 23:00:02 +00:00
hsbt d59fc41fba Fallback to load version constant for ruby core repository.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-07 12:32:29 +00:00
hsbt 7d9109f800 Removed needless date attribute from gemspec of default gems.
They are assigned automatically when pushing gem file to rubygems.org.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-07 12:02:10 +00:00
normal 9749bfbf73 webrick: Support bcrypt password hashing
This adds a password_hash keyword argument to
WEBrick::HTTPAuth::Htpasswd#initialize.  If set to :bcrypt, it
will create bcrypt hashes instead of crypt hashes, and will
raise an exception if the .htpasswd file uses crypt hashes.

If :bcrypt is used, then instead of calling
BasicAuth.make_passwd (which uses crypt),
WEBrick::HTTPAuth::Htpasswd#set_passwd will set the bcrypt
password directly.  It isn't possible to change the
make_passwd API to accept the password hash format, as that
would break configurations who use Htpasswd#auth_type= to set
a custom auth_type.

This modifies WEBrick::HTTPAuth::BasicAuth to handle checking
both crypt and bcrypt hashes.

There are commented out requires for 'string/crypt', to handle
when String#crypt is deprecated and the undeprecated version is
moved to a gem.

There is also a commented out warning for the case when
the password_hash keyword is not specified and 'string/crypt'
cannot be required.  I think the warning makes sense to nudge
users to using bcrypt.

I've updated the tests to test nil, :crypt, and :bcrypt values
for the password_hash keyword, skipping the bcrypt tests if the
bcrypt library cannot be required.

[ruby-core:88111] [Feature #14940]

From: Jeremy Evans <code@jeremyevans.net>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-26 03:21:52 +00:00
normal b9f9986a5e webrick/httpresponse: set_redirect requires a valid URI
Prevents response splitting and HTML injection attacks in
poorly-written applications which blindly pass along user input
in redirects.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63964 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-14 02:59:39 +00:00
ko1 1751ea76a4 repatch r62966 and r62969.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-03 10:22:45 +00:00
naruse 0c632c6fd3 Revert r62966 and r62969
It breaks mswin's test-all

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63069 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-03 07:54:18 +00:00
usa c1718e988e get rid of test error/failure on Windows introduced at r62955
* lib/webrick/httpresponse.rb (send_body_io): use seek if NotImplementedError
  is raised in IO.copy_stream with offset.

* lib/webrick/httpservlet/filehandler.rb (multipart_body): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 13:27:35 +00:00
normal d9d4a28f1c webrick: prevent response splitting and header injection
Original patch by tenderlove (with minor style adjustments).

* lib/webrick/httpresponse.rb (send_header): call check_header
  (check_header): raise on embedded CRLF in header value
* test/webrick/test_httpresponse.rb
  (test_prevent_response_splitting_headers): new test
* (test_prevent_response_splitting_cookie_headers): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 08:38:26 +00:00
normal 706c028909 webrick/httpproxy: stream request and response bodies
Reading entire request or response bodies into memory can lead
to trivial denial-of-service attacks.  Introduce Fibers in both
cases to allow streaming.

WEBrick::HTTPRequest gains a new body_reader method to prepare
itself as a source for IO.copy_stream.  This allows the
WEBrick::HTTPRequest object to be used as the
Net::HTTPGenericRequest#body_stream= arg for Net::HTTP.

For HTTP proxy response bodies, we also use a Fiber to
to make the HTTP request and read the response body.

* lib/webrick/httprequest.rb (body_reader): new method
  (readpartial): ditto
* lib/webrick/httpproxy.rb (perform_proxy_request): use Fiber
  to stream response body
  (do_GET, do_HEAD): adjust call
  (do_POST): adjust call and supply body_reader
* test/webrick/test_httprequest.rb (test_chunked): test
  for IO.copy_stream compatibility
* test/webrick/test_httpproxy.rb (test_big_bodies): new test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 08:06:55 +00:00
normal 32e277acbf webrick/httpauth/digestauth: stream req.body
WARNING! WARNING! WARNING!  LIKELY BROKEN CHANGE

Pass a proc to WEBrick::HTTPRequest#body to avoid reading a
potentially large request body into memory during
authentication.

WARNING! this will break apps completely which want to do
something with the body besides calculating the MD5 digest
of it.

Also, keep in mind that probably nobody uses "auth-int".
Servers such as Apache, lighttpd, nginx don't seem to
support it; nor does curl when using POST/PUT bodies;
and we didn't have tests for it until now...

* lib/webrick/httpauth/digestauth.rb (_authenticate): stream req.body

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 08:06:49 +00:00
normal 2d41d88c4d webrick/httprequest: use InputBufferSize for chunked requests
While WEBrick::HTTPRequest#body provides a Proc interface
for streaming large request bodies, clients must not force
the server to use an excessively large chunk size.

* lib/webrick/httprequest.rb (read_chunk_size): limit each
  read and block.call to :InputBufferSize in config.
* test/webrick/test_httpserver.rb (test_big_chunks): new test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 08:06:39 +00:00
normal 6db6eb572b webrick/httprequest: raise correct exception
"BadRequest" alone does not resolve correctly, it is in the
HTTPStatus namespace.

* lib/webrick/httprequest.rb (read_chunked): use correct exception
* test/webrick/test_httpserver.rb (test_eof_in_chunk): new test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 08:06:34 +00:00
normal 89450a80fc webrick/httpservlet/cgihandler: reduce memory use
WEBrick::HTTPRequest#body can be passed a block to process the
body in chunks.  Use this feature to avoid building a giant
string in memory.

* lib/webrick/httpservlet/cgihandler.rb (do_GET):
  avoid reading entire request body into memory
  (do_POST is aliased to do_GET, so it handles bodies)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 08:06:28 +00:00
normal 7e1f2a5aa9 webrick/httprequest: limit request headers size
We use the same 112 KB limit started (AFAIK) by Mongrel, Thin,
and Puma to prevent malicious users from using up all the memory
with a single request.  This also limits the damage done by
excessive ranges in multipart Range: requests.

Due to the way we rely on IO#gets and the desire to keep
the code simple, the actual maximum header may be 4093 bytes
larger than 112 KB, but we're splitting hairs at that point.

* lib/webrick/httprequest.rb: define MAX_HEADER_LENGTH
  (read_header): raise when headers exceed max length

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 08:06:23 +00:00
normal 4639ac8953 webrick: use IO.copy_stream for multipart response
Use the new Proc response body feature to generate a multipart
range response dynamically.  We use a flat array to minimize
object overhead as much as possible; as many ranges may fit
into an HTTP request header.

* lib/webrick/httpservlet/filehandler.rb (multipart_body): new method
  (make_partial_content): use multipart_body

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 08:06:18 +00:00
normal d6c0b3d787 webrick/httpresponse: make ChunkedWrapper copy_stream-compatible
The .write method needs to return the number of bytes written
to avoid confusing IO.copy_stream.

* lib/webrick/httpresponse.rb (ChunkedWrapper#write): return bytes written
  (ChunkedWrapper#<<): return self

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 08:06:13 +00:00
normal 6676a217f3 webrick: quiet warning for multi-part ranges
Content-Length is ignored by WEBrick::HTTPResponse even if we
calculate it, so instead we chunk responses to HTTP/1.1 clients
and terminate HTTP/1.0 connections.

* lib/webrick/httpservlet/filehandler.rb (make_partial_content):
  quiet warning

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 08:06:08 +00:00
normal 6360243fd2 webrick: use IO.copy_stream for single range response
This is also compatible with range responses generated
by Rack::File (tested with rack 2.0.3).

* lib/webrick/httpresponse.rb (send_body_io): use Content-Range
* lib/webrick/httpservlet/filehandler.rb (make_partial_content):
  use File object for the single range case
* test/webrick/test_filehandler.rb (get_res_body): use send_body
  to test result

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 08:05:57 +00:00
normal 2bdcd0bdde webrick/httpresponse: IO.copy_stream for regular files
Remove the redundant _send_file method since its functionality
is unnecessary with IO.copy_stream.  IO.copy_stream also allows
the use of sendfile under some OSes to speed up copies to
non-TLS sockets.

Testing with "curl >/dev/null" and "ruby -run -e httpd" to
read a 1G file over Linux loopback reveals a reduction from
around ~0.770 to ~0.490 seconds on the client side.

* lib/webrick/httpresponse.rb (send_body_io): use IO.copy_stream
  (_send_file): remove
  [Feature #14237]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62954 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 08:05:52 +00:00
normal c44978b99f webrick: favor .write over << method
This will make the next change to use IO.copy_stream
easier-to-read.  When we can drop Ruby 2.4 support in a few
years, this will allow us to use writev(2) with multiple
arguments for headers and chunked responses.

* lib/webrick/cgi.rb (write): new wrapper method
  lib/webrick/httpresponse.rb: (send_header): use socket.write
  (send_body_io): ditto
  (send_body_string): ditto
  (send_body_proc): ditto
  (_write_data): ditto
  (ChunkedWrapper#write): ditto
  (_send_file): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62953 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 08:05:46 +00:00
normal 7d10b978c3 webrick 1.4.2
This release removes uses of Kernel#open to avoid unintended
behaviors and make future auditing easier. [Misc #14216]

6 changes since 1.4.1:

      webrick: httpauth requires regular files
      webrick/httpservlet/cgi_runner.rb: remove unnecessary open
      webrick: WEBrick::Log requires path arg when given string
      webrick/httpservlet/*handler: use File.open
      webrick/httputils: note Kernel#open behavior
      webrick/httpservelet/cgi_runner: avoid IO#reopen on pathname

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-24 08:38:43 +00:00
normal 0d92f156b6 webrick/httpservelet/cgi_runner: avoid IO#reopen on pathname
IO#reopen seems to behave strangely on Win32 based on the logs
posted by Greg for [Bug #14420].  Lets try to fix the issue by
using File.open explicitly (but not Kernel#open).

* lib/webrick/httpservelet/cgi_runner: use File.open explicitly
  [Bug #14220]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-22 05:59:11 +00:00
normal f2aa7f409a webrick/httputils: note Kernel#open behavior
I don't know who uses the load_mime_types method; but it is
conceivable that a user would want to read the results of a
command instead of reading a regular file to load MIME types.

None of the WEBrick-related code in Ruby or default/bundled gems
seems to rely on this method; but it is likely 3rd-party code does.

* lib/webrick/httputils.rb (load_mime_types): note Kernel#open behavior
  [Misc #14216]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-22 01:08:05 +00:00
normal 1ad355bd53 webrick/httpservlet/*handler: use File.open
This makes future code audits easier.  None of these changes
fix realistic remote code execution vulnerabilities because
we stat(2) before attempting Kernel#open.

* lib/webrick/httpservlet/erbhandler.rb (do_GET): use File.open
* lib/webrick/httpservlet/filehandler.rb (do_GET): use File.open
  (make_partial_content): ditto
  [Misc #14216]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-22 01:08:00 +00:00
normal 1989371d10 webrick: WEBrick::Log requires path arg when given string
Allowing a user to specify "| command" via Kernel#open is
nonsensical since we never read from the resultant IO.

* lib/webrick/log.rb (initialize): replace Kernel#open with File.open
  [Misc #14216]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-22 01:07:55 +00:00
normal 646b83af2a webrick/httpservlet/cgi_runner.rb: remove unnecessary open
IO#reopen already takes string path names as well as IO objects
(but not "| command" strings)

This makes further auditing for inadvertant code execution
easier.  There's no actual bugfix or behavior change here,
as no external data is passed to cgi_runner.rb.

* lib/webrick/httpservlet/cgi_runner.rb: remove Kernel#open call
  [Misc #14216]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-22 01:07:45 +00:00
normal edddc28f62 webrick: httpauth requires regular files
Be sure we do not try to open a pipe to read from, since we care
about mtime in all cases.

* lib/webrick/httpauth/htdigest.rb: use File.open
* lib/webrick/httpauth/htgroup.rb: ditto
* lib/webrick/httpauth/htpasswd.rb: ditto
  [Misc #14216]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-22 01:07:39 +00:00
normal 74ceabb3b2 webrick 1.4.1 release
* lib/webrick/version.rb: bump version
* lib/webrick/webrick.gemspec: support Ruby 2.3+
  [Bug #14189]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-18 08:54:30 +00:00
normal 9cbb3bd1f2 webrick 1.4.0 release
* lib/webrick/version.rb: change VERSION to 1.4.0
* lib/webrick/webrick.gemspec: require_relative for version,
  update date and contact info
  [Feature #13173]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61266 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-14 20:02:15 +00:00
normal aac91cb762 webrick: compile RE correctly for beginning and end match
Using ^ and $ in regexps means we can accidentally get fooled
by "%0a" in HTTP request paths being decoded to newline
characters.  Use \A and \z to match beginning and end-of-string
respectively, instead.

Thanks to mame and hsbt for reporting.

* lib/webrick/httpserver.rb (MountTable#compile):
  use \A and \z instead of ^ and $
* lib/webrick/httpserver.rb (MountTable#normalize): use \z instead of $
* test/webrick/test_httpserver.rb (test_cntrl_in_path): new test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-13 00:38:08 +00:00
shyouhei f2a91397fd Add uplevel keyword to Kernel#warn and use it
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-12-12 11:56:25 +00:00
hsbt 84db29cea1 Ignore gemspec under the lib directory for documentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12 08:34:13 +00:00
normal 22474d8f96 webrick: allow shutdown after StartCallback
We must to ensure the @status ivar is set to :Running before
running StartCallback, otherwise Webrick::Server#stop will not
change the @status to :Shutdown properly.

Note: I have not been able to reproduce the original issue but
understood at least part of the problem and fixed it with this
commit.  However, the original reporter (Peak Xu) was still able
to reproduce the problem on 1.9.2 p180 on Windows, so I'm not
sure what else might be going on.  Ruby threading and
synchronization primitives have changed a lot since 1.9.2, so
maybe that was fixed elsewhere.

* lib/webrick/server.rb: call StartCallback sooner [Bug #4841]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-08 18:51:56 +00:00
normal 3b92c63158 webrick/httpresponse: minor cleanups to reduce memory use
I never knew "format" was a global method alias for "sprintf";
so it was confusing to me.  Normally, one would use "sprintf"
since it's also available in many other languages, but
Integer#to_s avoids parsing a format string so it's less
bug-prone.

Furthermore, favor string interpolation over String#<< since it
is easier for the VM to optimize memory allocation (as in r60320).
Interpolation also reduces method calls and memory overhead
for inline method cache.

Finally, ensure we clear all short-lived buffers for body
responses.  A similar change was made and measured for Net::*
in r58840 showing a large memory reduction on some workloads.

* webrick/httpresponse.rb (send_body_io): favor String#to_s,
  reduce method calls for String#<<,
  clear `buf' when done,
  avoid extra String#bytesize calls

* (send_body_string): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-31 01:37:37 +00:00
normal bb88b1aab8 webrick: support Proc objects as body responses
* lib/webrick/httpresponse.rb (send_body): call send_body_proc
  (send_body_proc): new method
  (class ChunkedWrapper): new class

* test/webrick/test_httpresponse.rb (test_send_body_proc): new test
  (test_send_body_proc_chunked): ditto
  [Feature #855]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-30 23:56:44 +00:00
normal cda27e1a6d webrick: fix up r60172 and r60210
Thanks to MSP-Greg (Greg L) for helping with this.

* lib/webrick/server.rb (start_thread): properly fix non-local return
  introduced in r60208 and r60210

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60211 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-18 23:34:02 +00:00
normal 834c252e5e webrick: fix up r60172 and r60208
Thanks to MSP-Greg (Greg L) for helping with this.

* lib/webrick/server.rb (start_thread): fix non-local return
  introduced in r60208

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-18 23:23:33 +00:00
normal 3b1db7d319 webrick: fix up r60172 and revert r60189
Thanks to MSP-Greg (Greg L) for helping with this.

* lib/webrick/server.rb (start_thread): ignore ECONNRESET, ECONNABORTED,
  EPROTO, and EINVAL on TLS negotiation errors the same way they
  were ignored before r60172 in the accept_client method of the
  main acceptor thread.
  [Bug #14013] [Bug #14005]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-18 21:45:34 +00:00