1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
Commit graph

19 commits

Author SHA1 Message Date
MSP-Greg
e2ef83b4ee
Allow header values to be arrays (Rack 3) (#2936)
* request.rb - allow header array value

* test_response_header.rb - add test
2022-09-09 14:05:47 +09:00
Blake Williams
b2283d8f25
Fix rack.after_reply exceptions breaking connections (#2861)
* Fix rack.after_reply exceptions breaking connections

Currently, when a `rack.after_reply` callable raises an exception we
attempt to handle it like other client errors by responding with an HTTP
500 response. This however doesn't work because `rack.after_reply`
callbacks are called after the response body has already been written to
the client.

This can cause issues with re-used connections. This is because 2 HTTP
responses are being returned for a single request. If a second HTTP
request is made before the error handling logic completes the timing can
line up causing the second HTTP response to be served a 500 from the
first HTTP requests `rack.after_reply` callbacks raising.

That may look roughly like:

1. Request 1 starts, opening a reusable TCP connection
2. Request 1 is written to and "completed"
3. Request 1 `rack.after_reply` callables are called
4. Request 2 starts, reusing the same TCP connection as request 1
5. `rack.after_reply` raises, calls `client_error` and serves a 500
   response
6. Request 2 receives the 500 response.

This is somewhat difficult to reproduce using HTTP clients since it's a
race condition whether or not the 500 is written at the "correct" time
or not.

To prevent this issue the `rack.after_reply` callables are now wrapped
in a begin/rescue/end block that rescues from `StandardError` and logs
instead of attempting to serve a 500 response.

* Assert against less specific exception
2022-04-17 10:21:36 -06:00
James Brown
a39388d9fa
use the connected family to determine whether to show IPv4 or IPv6 unspec/localhost addresses 2022-03-07 15:00:37 -08:00
James Brown
612a812c09
when using remote_addr_header, default to the physical peeraddr instead of LOCALHOST; when the client disconects unexpectedly, default to the unspecified source IP instead of localhost 2022-03-07 15:00:34 -08:00
Jean Boussier
b70f451fe8
Ensure close is called on the response body no matter what
Another fallout from https://github.com/puma/puma/pull/2809 is that
in some cases the `res_body.close` wasn't called because some previous code
raised.

For Rails apps it means CurrentAttributes and a few other important
states aren't reset properly.

This is being improved on the Rails side too, but I believe it would
be good to harden this on the puma side as well.
2022-02-11 12:51:26 -08:00
Johnny Shields
8a4ef0c16c
[WIP] Refactor: Split out LogWriter from Events (no logic change) (#2798)
* Split out LogWriter from Events

* Improve code comment

* Fix constructor interfaces

* Fix file includes

* Fix specs and requires

* Fix LogWriter

* More fixes

* Fix tests

* Fix specs

* Fix spec

* Fix more specs

* Refactor: Split out LogWriter from Events

* Improve comments

* Fix bundle pruner

Co-authored-by: shields <shields@tablecheck.com>
2022-02-05 10:06:22 -07:00
Samuel Williams
a63c0faf33
Add support for streaming bodies. (#2740)
* Add support for streaming bodies.

* Added a test

Co-authored-by: Nate Berkopec <nate.berkopec@gmail.com>
2022-01-29 10:15:36 -07:00
Patrik Ragnarsson
7008a61ac9
Revert "Always send lowlevel_error response to client (#2731)" (#2809)
This reverts commit f8acac1f07.

In response to https://github.com/puma/puma/issues/2808
2022-01-26 16:45:54 -07:00
Anders Bälter
f8acac1f07
Always send lowlevel_error response to client (#2731)
* Always send lowlevel_error response to client

* Add spec for lowlever error handler

* Make sure we have a clean buffer when starting response

* Simplify test

* Rename spec

* Add method docs

* Tweak the test

* Return 500 from lowlevel_error_handler in test

Co-authored-by: Patrik Ragnarsson <patrik@starkast.net>
2021-11-02 14:54:22 -05:00
MSP-Greg
6e4257fece
Replace IO.select with IO#wait_* when checking a single IO (#2666)
* Replace IO.select with IO#wait_* when checking a single IO

* helpers/integration.rb - fix Darwin UNIXSocket errors
2021-07-25 13:27:20 -06:00
Nate Berkopec
f418a6809a
Add Rubocop for redundant returns 2021-06-10 12:28:35 -06:00
MSP-Greg
32852f715a
Add rack_url_scheme to Puma::DSL, allows setting of rack.url_scheme header (#2586)
* Add rack_url_scheme to Puma::DSL, allows setting of rack.url_scheme header

* Clarify comment on DSL re: rack URL

* Add tests to test_puma_server.rb

Co-authored-by: Nate Berkopec <nate.berkopec@gmail.com>
2021-05-26 08:15:08 -06:00
Will Jordan
ffa5d56b84
Improvements to keepalive-connection shedding (#2628)
* Improvements to keepalive-connection shedding

* alternative still using max_fast_inline

* fix
2021-05-20 10:16:02 -06:00
Pascal Betz
51a82b5e6d
Improve parsing of HTTP_HOST header (#2605)
* Improve parsing of HTTP_HOST header

IPV6 Host was not properly parsed.

https://github.com/puma/puma/issues/2584

* Extracted Regex to constant

* Incorporate feedback

IPV6 are bracketed but contain colons so I needed to adapt the logic to separate host/port.

Co-authored-by: pascal betz <pascal.betz@swisscom.com>
2021-04-26 08:36:23 -06:00
MSP-Greg
403975b372
request.rb - fix chunked assembly for ascii incompatible encodings, add test (#2585)
Fix TestPumaServer#test_custom_io_selector
2021-03-25 17:22:06 -07:00
MSP-Greg
e3380e9b53
server.rb - properly cork & uncork ssl client (#2550) 2021-02-05 15:06:30 -07:00
Chien-Wei Huang (Michael)
31c72cf33e
Ignore illegal response header (#2439)
* Ignore illegal response header
2020-10-26 16:02:13 -06:00
MSP-Greg
5432a7cfc4
Request#req_env_post_parse - fixup comments [skip ci] 2020-10-09 12:17:28 -05:00
MSP-Greg
7dc7febf9d
Extract req/resp methods to new request.rb from server.rb (#2419) 2020-10-09 08:09:48 -06:00