sinatra 2.1.0 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +80 -0
- data/Gemfile +4 -5
- data/MAINTENANCE.md +2 -15
- data/README.de.md +13 -13
- data/README.es.md +59 -30
- data/README.ja.md +61 -31
- data/README.md +27 -27
- data/README.pt-br.md +60 -60
- data/VERSION +1 -1
- data/lib/sinatra/base.rb +54 -45
- data/lib/sinatra/indifferent_hash.rb +14 -0
- data/lib/sinatra/version.rb +1 -1
- data/sinatra.gemspec +3 -9
- metadata +11 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80e0d4f746b7bf91aecaa4af649cb63f04212975287e6ef37288a9e71e73a4ec
|
4
|
+
data.tar.gz: 5fcda18c311ca7ba08a2cbdf9ed60f97ed564bc9d54af4b600a86c2c6103ddc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82d744ca87a984b3e96175269d1225184f885f8ae052c1089cc2973fb740376ca354579fd1c463ad4accb38e9c27bc200d0344290258ecdeb7d347b81a3ab7f6
|
7
|
+
data.tar.gz: 8242b52ec226acf2c29fc902b9d5855c7090f60191c874b1fbaf68ead68b15ad47257a0bfdfd2648173f8545158b2cab7fe262ff74a2d3e0d9a692b84dfd8c32
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,83 @@
|
|
1
|
+
## 2.2.3 / 2022-11-25
|
2
|
+
|
3
|
+
* Fix: Escape filename in the Content-Disposition header. [#1841](https://github.com/sinatra/sinatra/pull/1841) by Kunpei Sakai
|
4
|
+
|
5
|
+
## 2.2.2 / 2022-07-23
|
6
|
+
|
7
|
+
* Update mustermann dependency to version 2.
|
8
|
+
|
9
|
+
## 2.2.1 / 2022-07-15
|
10
|
+
|
11
|
+
* Fix JRuby regression by using ruby2_keywords for delegation. [#1750](https://github.com/sinatra/sinatra/pull/1750) by Patrik Ragnarsson
|
12
|
+
|
13
|
+
* Add JRuby to CI. [#1755](https://github.com/sinatra/sinatra/pull/1755) by Karol Bucek
|
14
|
+
|
15
|
+
## 2.2.0 / 2022-02-15
|
16
|
+
|
17
|
+
* Breaking change: Add #select, #reject and #compact methods to Sinatra::IndifferentHash. If hash keys need to be converted to symbols, call #to_h to get a Hash instance first. #1711 by Olivier Bellone
|
18
|
+
|
19
|
+
* Handle EOFError raised by Rack and return Bad Request 400 status. [#1743](https://github.com/sinatra/sinatra/pull/1743) by tamazon
|
20
|
+
|
21
|
+
* Update README.es.md with removal of Thin. [#1630](https://github.com/sinatra/sinatra/pull/1630) by Espartaco Palma
|
22
|
+
|
23
|
+
* Minor refactors in `base.rb`. [#1640](https://github.com/sinatra/sinatra/pull/1640) by ceclinux
|
24
|
+
|
25
|
+
* Fixed typos in german README.md. [#1648](https://github.com/sinatra/sinatra/pull/1648) by Juri
|
26
|
+
|
27
|
+
* Add escaping to the static 404 page. [#1645](https://github.com/sinatra/sinatra/pull/1645) by Chris Gavin
|
28
|
+
|
29
|
+
* Remove `detect_rack_handler` method. [#1652](https://github.com/sinatra/sinatra/pull/1652) by ceclinux
|
30
|
+
|
31
|
+
* Respect content type set in superclass before filter. Fixes [#1647](https://github.com/sinatra/sinatra/issues/1647) [#1649](https://github.com/sinatra/sinatra/pull/1649) by Jordan Owens
|
32
|
+
|
33
|
+
* Update README.ja.md with removal of Thin. [#1629](https://github.com/sinatra/sinatra/pull/1629) by Ryuichi KAWAMATA
|
34
|
+
|
35
|
+
* *Revert "Use prepend instead of include for helpers.* [#1662](https://github.com/sinatra/sinatra/pull/1662) by namusyaka
|
36
|
+
|
37
|
+
* Various minor fixes to README.md. [#1663](https://github.com/sinatra/sinatra/pull/1663) by Yanis Zafirópulos
|
38
|
+
|
39
|
+
* Document when `dump_errors` is enabled. Fixes [#1664](https://github.com/sinatra/sinatra/issues/1664) [#1665](https://github.com/sinatra/sinatra/pull/1665) by Patrik Ragnarsson
|
40
|
+
|
41
|
+
* Update README.pt-br.md. [#1668](https://github.com/sinatra/sinatra/pull/1668) by Vitor Oliveira
|
42
|
+
|
43
|
+
* Fix usage of inherited `Sinatra::Base` classes keyword arguments. Fixes [#1669](https://github.com/sinatra/sinatra/issues/1669) [#1670](https://github.com/sinatra/sinatra/pull/1670) by Cadu Ribeiro
|
44
|
+
|
45
|
+
* Reduce RDoc generation time by not including every README. Fixes [#1578](https://github.com/sinatra/sinatra/issues/1578) [#1671](https://github.com/sinatra/sinatra/pull/1671) by Eloy Pérez
|
46
|
+
|
47
|
+
* Add support for per form csrf tokens. Fixes [#1616](https://github.com/sinatra/sinatra/issues/1616) [#1653](https://github.com/sinatra/sinatra/pull/1653) by Jordan Owens
|
48
|
+
|
49
|
+
* Update MAINTENANCE.md with the `stable` branch status. [#1681](https://github.com/sinatra/sinatra/pull/1681) by Fredrik Rubensson
|
50
|
+
|
51
|
+
* Validate expanded path matches `public_dir` when serving static files. [#1683](https://github.com/sinatra/sinatra/pull/1683) by cji-stripe
|
52
|
+
|
53
|
+
* Fix Delegator to pass keyword arguments for Ruby 3.0. [#1684](https://github.com/sinatra/sinatra/pull/1684) by andrewtblake
|
54
|
+
|
55
|
+
* Fix use with keyword arguments for Ruby 3.0. [#1701](https://github.com/sinatra/sinatra/pull/1701) by Robin Wallin
|
56
|
+
|
57
|
+
* Fix memory leaks for proc template. Fixes [#1704](https://github.com/sinatra/sinatra/issues/1714) [#1719](https://github.com/sinatra/sinatra/pull/1719) by Slevin
|
58
|
+
|
59
|
+
* Remove unnecessary `test_files` from the gemspec. [#1712](https://github.com/sinatra/sinatra/pull/1712) by Masataka Pocke Kuwabara
|
60
|
+
|
61
|
+
### CI
|
62
|
+
|
63
|
+
* Use latest JRuby 9.2.16.0 on CI. [#1682](https://github.com/sinatra/sinatra/pull/1682) by Olle Jonsson
|
64
|
+
|
65
|
+
* Switch CI from travis to Github actions. [#1691](https://github.com/sinatra/sinatra/pull/1691) by namusyaka
|
66
|
+
|
67
|
+
* Skip the Slack action if `secrets.SLACK_WEBHOOK` is not set. [#1705](https://github.com/sinatra/sinatra/pull/1705) by Robin Wallin
|
68
|
+
|
69
|
+
* Small CI improvements. [#1703](https://github.com/sinatra/sinatra/pull/1703) by Robin Wallin
|
70
|
+
|
71
|
+
* Drop auto-generated boilerplate comments from CI configuration file. [#1728](https://github.com/sinatra/sinatra/pull/1728) by Olle Jonsson
|
72
|
+
|
73
|
+
### sinatra-contrib
|
74
|
+
|
75
|
+
* Do not raise when key is an enumerable. [#1619](https://github.com/sinatra/sinatra/pull/1619) by Ulysse Buonomo
|
76
|
+
|
77
|
+
### Rack protection
|
78
|
+
|
79
|
+
* Fix broken `origin_whitelist` option. Fixes [#1641](https://github.com/sinatra/sinatra/issues/1641) [#1642](https://github.com/sinatra/sinatra/pull/1642) by Takeshi YASHIRO
|
80
|
+
|
1
81
|
## 2.1.0 / 2020-09-05
|
2
82
|
|
3
83
|
* Fix additional Ruby 2.7 keyword warnings [#1586](https://github.com/sinatra/sinatra/pull/1586) by Stefan Sundin
|
data/Gemfile
CHANGED
@@ -11,7 +11,7 @@ source 'https://rubygems.org' unless ENV['QUICK']
|
|
11
11
|
gemspec
|
12
12
|
|
13
13
|
gem 'rake'
|
14
|
-
gem 'rack',
|
14
|
+
gem 'rack', '~> 2.0'
|
15
15
|
gem 'rack-test', '>= 0.6.2'
|
16
16
|
gem "minitest", "~> 5.0"
|
17
17
|
gem 'yard'
|
@@ -23,7 +23,7 @@ gem "twitter-text", "1.14.7"
|
|
23
23
|
|
24
24
|
if RUBY_ENGINE == 'jruby'
|
25
25
|
gem 'nokogiri', '!= 1.5.0'
|
26
|
-
gem '
|
26
|
+
gem 'puma', '~> 5'
|
27
27
|
end
|
28
28
|
|
29
29
|
if RUBY_ENGINE == 'jruby' || RUBY_ENGINE == 'ruby'
|
@@ -34,18 +34,17 @@ if RUBY_ENGINE == "ruby"
|
|
34
34
|
gem 'less', '~> 2.0'
|
35
35
|
gem 'therubyracer'
|
36
36
|
gem 'redcarpet'
|
37
|
-
gem 'wlang', '>=
|
37
|
+
gem 'wlang', '>= 3.0.1'
|
38
38
|
gem 'bluecloth'
|
39
39
|
gem 'rdiscount'
|
40
40
|
gem 'RedCloth'
|
41
|
-
gem 'puma'
|
41
|
+
gem 'puma', '~> 5'
|
42
42
|
gem 'yajl-ruby'
|
43
43
|
gem 'nokogiri'
|
44
44
|
gem 'rainbows'
|
45
45
|
gem 'eventmachine'
|
46
46
|
gem 'slim', '~> 2.0'
|
47
47
|
gem 'coffee-script', '>= 2.0'
|
48
|
-
gem 'rdoc'
|
49
48
|
gem 'kramdown'
|
50
49
|
gem 'maruku'
|
51
50
|
gem 'creole'
|
data/MAINTENANCE.md
CHANGED
@@ -2,15 +2,9 @@
|
|
2
2
|
|
3
3
|
## Versions
|
4
4
|
|
5
|
-
###
|
5
|
+
### Releases
|
6
6
|
|
7
|
-
The next major version of Sinatra will be released from the master branch.
|
8
|
-
|
9
|
-
* Current proposed major release: 2.0.0
|
10
|
-
|
11
|
-
### Stable release
|
12
|
-
|
13
|
-
The current stable version of Sinatra is 1.4 series, and released from the stable branch.
|
7
|
+
The next major version of Sinatra will be released from the master branch. Each version will be tagged so it will be possible to branch of should there be a need for bug fixes and other updates.
|
14
8
|
|
15
9
|
## Issues
|
16
10
|
|
@@ -22,21 +16,14 @@ New features will only be added to the master branch and will not be made availa
|
|
22
16
|
|
23
17
|
Only the latest release series will receive bug fixes. When enough bugs are fixed and its deemed worthy to release a new gem, this is the branch it happens from.
|
24
18
|
|
25
|
-
* Current release series: 1.4.x
|
26
|
-
|
27
19
|
### Security issues
|
28
20
|
|
29
21
|
The current release series will receive patches and new versions in case of a security issue.
|
30
22
|
|
31
|
-
* Current release series: 1.4.x
|
32
|
-
|
33
23
|
### Severe security issues
|
34
24
|
|
35
25
|
For severe security issues we will provide new versions as above, and also the last major release series will receive patches and new versions. The classification of the security issue is judged by the core team.
|
36
26
|
|
37
|
-
* Current release series: 1.4.x
|
38
|
-
* Next most recent release series: 1.3.x
|
39
|
-
|
40
27
|
### Unsupported Release Series
|
41
28
|
|
42
29
|
When a release series is no longer supported, it’s your own responsibility to deal with bugs and security issues. We may provide back-ports of the fixes and publish them to git, however there will be no new versions released. If you are not comfortable maintaining your own versions, you should upgrade to a supported version.
|
data/README.de.md
CHANGED
@@ -35,7 +35,7 @@ ruby myapp.rb
|
|
35
35
|
Die Seite kann nun unter [http://localhost:4567](http://localhost:4567)
|
36
36
|
aufgerufen werden.
|
37
37
|
|
38
|
-
Es wird empfohlen `gem
|
38
|
+
Es wird empfohlen `gem install thin` auszuführen, Sinatra wird dann
|
39
39
|
diesen Server verwenden.
|
40
40
|
|
41
41
|
## Inhalt
|
@@ -362,7 +362,7 @@ einen Rack-Rückgabewert, einen Rack-Body oder einen HTTP-Status-Code handelt:
|
|
362
362
|
* Ein Array mit zwei Elementen: `[Status (Integer), Response-Body (antwortet
|
363
363
|
auf #each)]`.
|
364
364
|
* Ein Objekt, das auf `#each` antwortet und den an diese Methode übergebenen
|
365
|
-
Block nur mit Strings als
|
365
|
+
Block nur mit Strings als Übergabewerten aufruft.
|
366
366
|
* Ein Integer, das den Status-Code festlegt.
|
367
367
|
|
368
368
|
Damit lässt sich relativ einfach Streaming implementieren:
|
@@ -467,7 +467,7 @@ get '/' do
|
|
467
467
|
end
|
468
468
|
```
|
469
469
|
|
470
|
-
Templates nehmen ein
|
470
|
+
Templates nehmen ein zweites Argument an, den Options-Hash:
|
471
471
|
|
472
472
|
```ruby
|
473
473
|
get '/' do
|
@@ -1114,7 +1114,7 @@ end
|
|
1114
1114
|
</table>
|
1115
1115
|
|
1116
1116
|
Die Template-Quelle wird als Ruby-String evaluiert. Die daraus resultierende
|
1117
|
-
|
1117
|
+
Json-Variable wird mit Hilfe von `#to_json` umgewandelt:
|
1118
1118
|
|
1119
1119
|
```ruby
|
1120
1120
|
json = { :foo => 'bar' }
|
@@ -1438,16 +1438,16 @@ keinen Schlüssel zu verwenden, dessen Zufälligkeit weniger als 32 Bytes
|
|
1438
1438
|
entspricht (also 256 Bits, 64 Hex-Zeichen). Es ist deshalb **wirklich
|
1439
1439
|
wichtig**, dass nicht einfach irgendetwas als Schlüssel verwendet wird,
|
1440
1440
|
sondern ein sicherer Zufallsgenerator die Zeichenkette erstellt. Menschen sind
|
1441
|
-
nicht besonders gut, zufällige Zeichenfolgen zu erstellen.
|
1441
|
+
nicht besonders gut darin, zufällige Zeichenfolgen zu erstellen.
|
1442
1442
|
|
1443
|
-
Sinatra generiert automatisch einen zufälligen 32 Byte langen
|
1443
|
+
Sinatra generiert automatisch einen zufälligen, 32 Byte langen
|
1444
1444
|
Schlüssel. Da jedoch bei jedem Neustart der Schlüssel ebenfalls neu generiert
|
1445
1445
|
wird, ist es sinnvoll einen eigenen Schlüssel festzulegen, damit er über alle
|
1446
1446
|
Anwendungsinstanzen hinweg geteilt werden kann.
|
1447
1447
|
|
1448
1448
|
Aus praktikablen und Sicherheitsgründen wird
|
1449
1449
|
[empfohlen](https://12factor.net/config), dass ein sicherer Zufallswert
|
1450
|
-
erzeugt und in einer Umgebungsvariable
|
1450
|
+
erzeugt und in einer Umgebungsvariable abgelegt wird, damit alle
|
1451
1451
|
Anwendungsinstanzen darauf zugreifen können. Dieser Sitzungsschlüssel
|
1452
1452
|
sollte in regelmäßigen Abständen erneuert werden. Zum Erzeugen von 64
|
1453
1453
|
Byte starken Schlüsseln sind hier ein paar Beispiele vorgestellt:
|
@@ -1850,7 +1850,7 @@ get '/bar' do
|
|
1850
1850
|
end
|
1851
1851
|
```
|
1852
1852
|
|
1853
|
-
Um Argumente an
|
1853
|
+
Um Argumente an einen Redirect weiterzugeben, können sie entweder dem Query
|
1854
1854
|
übergeben:
|
1855
1855
|
|
1856
1856
|
```ruby
|
@@ -2083,7 +2083,7 @@ get '/' do
|
|
2083
2083
|
end
|
2084
2084
|
```
|
2085
2085
|
|
2086
|
-
Ebenso kann
|
2086
|
+
Ebenso kann ein Dateiname als Parameter hinzugefügt werden:
|
2087
2087
|
|
2088
2088
|
```ruby
|
2089
2089
|
get '/' do
|
@@ -2153,7 +2153,7 @@ helpers do
|
|
2153
2153
|
end
|
2154
2154
|
```
|
2155
2155
|
|
2156
|
-
Ein anderes Beispiel wäre, verschiedene
|
2156
|
+
Ein anderes Beispiel wäre, verschiedene Verzeichnisse für verschiedene Engines
|
2157
2157
|
zu verwenden:
|
2158
2158
|
|
2159
2159
|
```ruby
|
@@ -2175,7 +2175,7 @@ Beachte, dass `find_template` nicht prüft, ob eine Datei tatsächlich
|
|
2175
2175
|
existiert. Es wird lediglich der angegebene Block aufgerufen und nach allen
|
2176
2176
|
möglichen Pfaden gesucht. Das ergibt kein Performance-Problem, da `render`
|
2177
2177
|
`block` verwendet, sobald eine Datei gefunden wurde. Ebenso werden
|
2178
|
-
Template-Pfade samt
|
2178
|
+
Template-Pfade samt Inhalten gecached, solange nicht im Entwicklungsmodus
|
2179
2179
|
gearbeitet wird. Das sollte im Hinterkopf behalten werden, wenn irgendwelche
|
2180
2180
|
verrückten Methoden zusammengebastelt werden.
|
2181
2181
|
|
@@ -2306,7 +2306,7 @@ set :protection, session => true
|
|
2306
2306
|
|
2307
2307
|
<dt>bind</dt>
|
2308
2308
|
<dd>
|
2309
|
-
IP-
|
2309
|
+
IP-Adresse, an die gebunden wird (Standardwert: <tt>0.0.0.0</tt>
|
2310
2310
|
<em>oder</em> <tt>localhost</tt>). Wird nur für den eingebauten Server
|
2311
2311
|
verwendet.
|
2312
2312
|
</dd>
|
@@ -2439,7 +2439,7 @@ set :protection, session => true
|
|
2439
2439
|
|
2440
2440
|
<dt>show_exceptions</dt>
|
2441
2441
|
<dd>
|
2442
|
-
Bei Fehlern einen Stacktrace im
|
2442
|
+
Bei Fehlern einen Stacktrace im Browser anzeigen. Ist automatisch
|
2443
2443
|
aktiviert, wenn die Umgebung auf <tt>"development"</tt>
|
2444
2444
|
eingestellt ist. Ansonsten ist diese Option deaktiviert.
|
2445
2445
|
</dd>
|
data/README.es.md
CHANGED
@@ -33,7 +33,7 @@ Ver en [http://localhost:4567](http://localhost:4567).
|
|
33
33
|
El código que cambiaste no tendra efecto hasta que reinicies el servidor.
|
34
34
|
Por favor reinicia el servidor cada vez que cambies tu código o usa [sinatra/reloader](http://www.sinatrarb.com/contrib/reloader).
|
35
35
|
|
36
|
-
Se recomienda ejecutar `gem install
|
36
|
+
Se recomienda ejecutar `gem install puma`, porque Sinatra lo utilizará si está disponible.
|
37
37
|
|
38
38
|
|
39
39
|
## Tabla de Contenidos
|
@@ -1692,38 +1692,57 @@ Shotgun, el streaming no va a funcionar.
|
|
1692
1692
|
Cuando se pasa `keep_open` como parámetro, no se va a enviar el mensaje
|
1693
1693
|
`close` al objeto de stream. Permite que tu lo cierres en el punto de ejecución
|
1694
1694
|
que quieras. Nuevamente, hay que tener en cuenta que este comportamiento es
|
1695
|
-
posible
|
1695
|
+
posible sólo en servidores que soporten eventos, como Rainbows. El
|
1696
1696
|
resto de los servidores van a cerrar el stream de todos modos:
|
1697
1697
|
|
1698
1698
|
```ruby
|
1699
|
-
# long polling
|
1700
1699
|
|
1701
|
-
|
1702
|
-
|
1700
|
+
# config.ru
|
1701
|
+
require 'sinatra/base'
|
1703
1702
|
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
#
|
1709
|
-
|
1703
|
+
class App < Sinatra::Base
|
1704
|
+
connections = []
|
1705
|
+
|
1706
|
+
get '/subscribe' do
|
1707
|
+
# registrar a un cliente interesado en los eventos del servidor
|
1708
|
+
stream(:keep_open) do |out|
|
1709
|
+
connections << out
|
1710
|
+
# purgar conexiones muertas
|
1711
|
+
connections.reject!(&:closed?)
|
1712
|
+
end
|
1710
1713
|
end
|
1711
|
-
end
|
1712
1714
|
|
1713
|
-
post '/:message' do
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1715
|
+
post '/:message' do
|
1716
|
+
connections.each do |out|
|
1717
|
+
# notificar al cliente que ha llegado un nuevo mensaje
|
1718
|
+
out << params['message'] << "\n"
|
1719
|
+
|
1720
|
+
# indicar al cliente para conectarse de nuevo
|
1721
|
+
out.close
|
1722
|
+
end
|
1717
1723
|
|
1718
|
-
#
|
1719
|
-
|
1724
|
+
# reconocer
|
1725
|
+
"message received"
|
1720
1726
|
end
|
1727
|
+
end
|
1728
|
+
|
1729
|
+
run App
|
1730
|
+
```
|
1731
|
+
|
1732
|
+
```ruby
|
1733
|
+
# rainbows.conf
|
1721
1734
|
|
1722
|
-
|
1723
|
-
|
1735
|
+
Rainbows! do
|
1736
|
+
use :EventMachine
|
1724
1737
|
end
|
1725
1738
|
```
|
1726
1739
|
|
1740
|
+
Ejecute:
|
1741
|
+
|
1742
|
+
```shell
|
1743
|
+
rainbows -c rainbows.conf
|
1744
|
+
```
|
1745
|
+
|
1727
1746
|
También es posible que el cliente cierre la conexión cuando intenta
|
1728
1747
|
escribir en el socket. Debido a esto, se recomienda verificar con
|
1729
1748
|
`out.closed?` antes de intentar escribir.
|
@@ -2394,13 +2413,13 @@ set :protection, :except => [:path_traversal, :session_hijacking]
|
|
2394
2413
|
<dt>server</dt>
|
2395
2414
|
<dd>
|
2396
2415
|
Servidor, o lista de servidores, para usar como servidor
|
2397
|
-
integrado.
|
2398
|
-
|
2416
|
+
integrado. El orden indica su prioridad, por defecto depende
|
2417
|
+
de la implementación de Ruby.
|
2399
2418
|
</dd>
|
2400
2419
|
|
2401
2420
|
<dt>server_settings</dt>
|
2402
2421
|
<dd>
|
2403
|
-
Si está utilizando un servidor web WEBrick, presumiblemente para su entorno de desarrollo, puede pasar un hash de opciones a <tt> server_settings </tt>, como <tt> SSLEnable </tt> o <tt> SSLVerifyClient </tt>. Sin embargo, los servidores web como Puma
|
2422
|
+
Si está utilizando un servidor web WEBrick, presumiblemente para su entorno de desarrollo, puede pasar un hash de opciones a <tt> server_settings </tt>, como <tt> SSLEnable </tt> o <tt> SSLVerifyClient </tt>. Sin embargo, los servidores web como Puma no son compatibles, por lo que puede establecer <tt> server_settings </tt> definiéndolo como un método cuando llame a <tt> configure </tt>.
|
2404
2423
|
</dd>
|
2405
2424
|
|
2406
2425
|
<dt>sessions</dt>
|
@@ -2452,7 +2471,7 @@ información.
|
|
2452
2471
|
|
2453
2472
|
<dt>threaded</dt>
|
2454
2473
|
<dd>
|
2455
|
-
Si se establece en <tt> true </tt>, le dirá
|
2474
|
+
Si se establece en <tt> true </tt>, le dirá al servidor que use
|
2456
2475
|
<tt> EventMachine.defer </tt> para procesar la solicitud.
|
2457
2476
|
</dd>
|
2458
2477
|
|
@@ -3040,7 +3059,7 @@ Las opciones son:
|
|
3040
3059
|
-p # asigna el puerto (4567 es usado por defecto)
|
3041
3060
|
-o # asigna el host (0.0.0.0 es usado por defecto)
|
3042
3061
|
-e # asigna el entorno (development es usado por defecto)
|
3043
|
-
-s # especifica el servidor/manejador rack (
|
3062
|
+
-s # especifica el servidor/manejador rack (puma es usado por defecto)
|
3044
3063
|
-q # activar el modo silecioso para el servidor (está desactivado por defecto)
|
3045
3064
|
-x # activa el mutex lock (está desactivado por defecto)
|
3046
3065
|
```
|
@@ -3050,16 +3069,16 @@ Las opciones son:
|
|
3050
3069
|
_Basado en [esta respuesta en StackOverflow](http://stackoverflow.com/questions/6278817/is-sinatra-multi-threaded/6282999#6282999) escrita por Konstantin_
|
3051
3070
|
|
3052
3071
|
Sinatra no impone ningún modelo de concurrencia, sino que lo deja en manos del
|
3053
|
-
handler Rack que se esté usando (
|
3072
|
+
handler Rack que se esté usando (Puma o WEBrick). Sinatra en sí mismo es
|
3054
3073
|
thread-safe, así que no hay problema en que el Rack handler use un modelo de
|
3055
3074
|
concurrencia basado en hilos.
|
3056
3075
|
|
3057
3076
|
Esto significa que, cuando estemos arrancando el servidor, tendríamos que
|
3058
3077
|
especificar la opción adecuada para el handler Rack específico. En este ejemplo
|
3059
|
-
vemos cómo arrancar un servidor
|
3078
|
+
vemos cómo arrancar un servidor Rainbows multihilo:
|
3060
3079
|
|
3061
3080
|
```ruby
|
3062
|
-
#
|
3081
|
+
# config.ru
|
3063
3082
|
|
3064
3083
|
require 'sinatra/base'
|
3065
3084
|
|
@@ -3069,13 +3088,23 @@ class App < Sinatra::Base
|
|
3069
3088
|
end
|
3070
3089
|
end
|
3071
3090
|
|
3072
|
-
App
|
3091
|
+
run App
|
3092
|
+
```
|
3093
|
+
|
3094
|
+
```ruby
|
3095
|
+
# rainbows.conf
|
3096
|
+
|
3097
|
+
# El configurador de Rainbows está basado en Unicorn.
|
3098
|
+
|
3099
|
+
Rainbows! do
|
3100
|
+
use :ThreadSpawn
|
3101
|
+
end
|
3073
3102
|
```
|
3074
3103
|
|
3075
3104
|
Para arrancar el servidor, el comando sería:
|
3076
3105
|
|
3077
3106
|
```shell
|
3078
|
-
|
3107
|
+
rainbows -c rainbows.conf
|
3079
3108
|
```
|
3080
3109
|
|
3081
3110
|
## Requerimientos
|
data/README.ja.md
CHANGED
@@ -28,7 +28,10 @@ ruby myapp.rb
|
|
28
28
|
|
29
29
|
[http://localhost:4567](http://localhost:4567) を開きます。
|
30
30
|
|
31
|
-
|
31
|
+
コードを変更しても、サーバを再起動しないと変更が有効になりません。
|
32
|
+
コードを変更するたびにサーバを再起動するか、[sinatra/reloader](http://www.sinatrarb.com/contrib/reloader)を使ってください。
|
33
|
+
|
34
|
+
PumaがあればSinatraはこれを利用するので、`gem install puma`することをお薦めします。
|
32
35
|
|
33
36
|
## 目次
|
34
37
|
|
@@ -747,7 +750,7 @@ erb :overview, :locals => { :text => textile(:introduction) }
|
|
747
750
|
%p= textile(:greetings)
|
748
751
|
```
|
749
752
|
|
750
|
-
|
753
|
+
TextileからはRubyを呼ぶことができないので、Textileで書かれたレイアウトを使うことはできません。しかしながら、`:layout_engine`オプションを渡すことでテンプレートのものとは異なるレンダリングエンジンをレイアウトのために使うことができます。
|
751
754
|
|
752
755
|
#### RDoc テンプレート
|
753
756
|
|
@@ -1482,37 +1485,55 @@ end
|
|
1482
1485
|
|
1483
1486
|
これはストリーミングAPI、[Server Sent Events](https://w3c.github.io/eventsource/)の実装を可能にし、[WebSockets](https://en.wikipedia.org/wiki/WebSocket)の土台に使うことができます。また、一部のコンテンツが遅いリソースに依存しているときに、スループットを上げるために使うこともできます。
|
1484
1487
|
|
1485
|
-
ノート: ストリーミングの挙動、特に並行リクエスト(
|
1488
|
+
ノート: ストリーミングの挙動、特に並行リクエスト(concurrent requests)の数は、アプリケーションを提供するのに使われるWebサーバに強く依存します。いくつかのサーバは、ストリーミングを全くサポートしません。サーバがストリーミングをサポートしない場合、ボディは`stream`に渡されたブロックの実行が終了した後、一度に全部送られることになります。ストリーミングは、Shotgunを使った場合は全く動作しません。
|
1486
1489
|
|
1487
|
-
オプション引数が`keep_open`にセットされている場合、ストリームオブジェクト上で`close`は呼ばれず、実行フローの任意の遅れたタイミングでユーザがこれを閉じることを可能にします。これは
|
1490
|
+
オプション引数が`keep_open`にセットされている場合、ストリームオブジェクト上で`close`は呼ばれず、実行フローの任意の遅れたタイミングでユーザがこれを閉じることを可能にします。これはRainbowsのようなイベント型サーバ上でしか機能しません。他のサーバでは依然ストリームは閉じられます。
|
1488
1491
|
|
1489
1492
|
```ruby
|
1490
|
-
#
|
1491
|
-
|
1492
|
-
set :server, :thin
|
1493
|
-
connections = []
|
1493
|
+
# config.ru
|
1494
|
+
require 'sinatra/base'
|
1494
1495
|
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
#
|
1500
|
-
|
1496
|
+
class App < Sinatra::Base
|
1497
|
+
connections = []
|
1498
|
+
|
1499
|
+
get '/subscribe' do
|
1500
|
+
# register a client's interest in server events
|
1501
|
+
# サーバイベントにおけるクライアントの関心を登録
|
1502
|
+
stream(:keep_open) do |out|
|
1503
|
+
connections << out
|
1504
|
+
# 死んでいるコネクションを排除
|
1505
|
+
connections.reject!(&:closed?)
|
1506
|
+
end
|
1501
1507
|
end
|
1502
|
-
end
|
1503
1508
|
|
1504
|
-
post '
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1509
|
+
post '/:message' do
|
1510
|
+
connections.each do |out|
|
1511
|
+
# クライアントへ新規メッセージ到着の通知
|
1512
|
+
out << params['message'] << "\n"
|
1508
1513
|
|
1509
|
-
|
1510
|
-
|
1514
|
+
# クライアントへの再接続の指示
|
1515
|
+
out.close
|
1516
|
+
end
|
1517
|
+
|
1518
|
+
# 肯定応答
|
1519
|
+
"message received"
|
1511
1520
|
end
|
1521
|
+
end
|
1522
|
+
|
1523
|
+
run App
|
1524
|
+
```
|
1512
1525
|
|
1513
|
-
|
1514
|
-
|
1526
|
+
```ruby
|
1527
|
+
# rainbows.conf
|
1528
|
+
Rainbows! do
|
1529
|
+
use :EventMachine
|
1515
1530
|
end
|
1531
|
+
````
|
1532
|
+
|
1533
|
+
次のように起動します。
|
1534
|
+
|
1535
|
+
```shell
|
1536
|
+
rainbows -c rainbows.conf
|
1516
1537
|
```
|
1517
1538
|
|
1518
1539
|
クライアントはソケットに書き込もうとしている接続を閉じることも可能です。そのため、記述しようとする前に`out.closed?`をチェックすることを勧めます。
|
@@ -2107,7 +2128,7 @@ set :protection, :session => true
|
|
2107
2128
|
|
2108
2129
|
<dt>threaded</dt>
|
2109
2130
|
<dd>
|
2110
|
-
<tt>true</tt
|
2131
|
+
<tt>true</tt>に設定されているときは、サーバにリクエストを処理するために<tt>EventMachine.defer</tt>を使うことを通知する。
|
2111
2132
|
</dd>
|
2112
2133
|
|
2113
2134
|
<dt>views</dt>
|
@@ -2631,7 +2652,7 @@ ruby myapp.rb [-h] [-x] [-e ENVIRONMENT] [-p PORT] [-o HOST] [-s HANDLER]
|
|
2631
2652
|
-p # ポート指定(デフォルトは4567)
|
2632
2653
|
-o # ホスト指定(デフォルトは0.0.0.0)
|
2633
2654
|
-e # 環境を指定 (デフォルトはdevelopment)
|
2634
|
-
-s # rackserver/handlerを指定 (デフォルトは
|
2655
|
+
-s # rackserver/handlerを指定 (デフォルトはpuma)
|
2635
2656
|
-x # mutex lockを付ける (デフォルトはoff)
|
2636
2657
|
```
|
2637
2658
|
|
@@ -2640,13 +2661,13 @@ ruby myapp.rb [-h] [-x] [-e ENVIRONMENT] [-p PORT] [-o HOST] [-s HANDLER]
|
|
2640
2661
|
_この[StackOverflow](https://stackoverflow.com/a/6282999/5245129)
|
2641
2662
|
のKonstantinによる回答を言い換えています。_
|
2642
2663
|
|
2643
|
-
Sinatra
|
2664
|
+
Sinatraでは同時実行モデルを負わせることはできませんが、根本的な部分であるやPuma、WEBrickのようなRackハンドラ(サーバー)部分に委ねることができます。
|
2644
2665
|
Sinatra自身はスレッドセーフであり、もしRackハンドラが同時実行モデルのスレッドを使用していても問題はありません。
|
2645
2666
|
つまり、これはサーバーを起動させる時、特定のRackハンドラに対して正しい起動処理を特定することが出来ます。
|
2646
|
-
この例は
|
2667
|
+
この例はRainbowsサーバーをマルチスレッドで起動する方法のデモです。
|
2647
2668
|
|
2648
2669
|
```ruby
|
2649
|
-
#
|
2670
|
+
# config.ru
|
2650
2671
|
|
2651
2672
|
require 'sinatra/base'
|
2652
2673
|
|
@@ -2656,13 +2677,22 @@ class App < Sinatra::Base
|
|
2656
2677
|
end
|
2657
2678
|
end
|
2658
2679
|
|
2659
|
-
App
|
2680
|
+
run App
|
2681
|
+
```
|
2682
|
+
|
2683
|
+
```ruby
|
2684
|
+
# rainbows.conf
|
2685
|
+
|
2686
|
+
# RainbowsのコンフィギュレータはUnicornのものをベースにしています。
|
2687
|
+
Rainbows! do
|
2688
|
+
use :ThreadSpawn
|
2689
|
+
end
|
2660
2690
|
```
|
2661
2691
|
|
2662
|
-
|
2692
|
+
次のようなコマンドでサーバを起動します。
|
2663
2693
|
|
2664
2694
|
```
|
2665
|
-
|
2695
|
+
rainbows -c rainbows.conf
|
2666
2696
|
```
|
2667
2697
|
|
2668
2698
|
## 必要環境
|