Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 88
Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 215
Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 216
Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 217
Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 218
Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 219
Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 220
PK ! |7 7
bin/rackupnu ȯ #!/usr/bin/env ruby
require "rack"
Rack::Server.start
PK ! EG G example/lobster.runu [ require 'rack/lobster'
use Rack::ShowExceptions
run Rack::Lobster.new
PK ! ~u u example/protectedlobster.rbnu [ require 'rack'
require 'rack/lobster'
lobster = Rack::Lobster.new
protected_lobster = Rack::Auth::Basic.new(lobster) do |username, password|
'secret' == password
end
protected_lobster.realm = 'Lobster 2.0'
pretty_protected_lobster = Rack::ShowStatus.new(Rack::ShowExceptions.new(protected_lobster))
Rack::Server.start :app => pretty_protected_lobster, :Port => 9292
PK ! OK!` example/protectedlobster.runu [ require 'rack/lobster'
use Rack::ShowExceptions
use Rack::Auth::Basic, "Lobster 2.0" do |username, password|
'secret' == password
end
run Rack::Lobster.new
PK ! CrGA A KNOWN-ISSUESnu [ = Known issues with Rack and ECMA-262
* Many users expect the escape() function defined in ECMA-262 to be compatible
with URI. Confusion is especially strong because the documentation for the
escape function includes a reference to the URI specifications. ECMA-262
escape is not however a URI escape function, it is a javascript escape
function, and is not fully compatible. Most notably, for characters outside of
the BMP. Users should use the more correct encodeURI functions.
= Known issues with Rack and Web servers
* Lighttpd sets wrong SCRIPT_NAME and PATH_INFO if you mount your
FastCGI app at "/". This can be fixed by using this middleware:
class LighttpdScriptNameFix
def initialize(app)
@app = app
end
def call(env)
env["PATH_INFO"] = env["SCRIPT_NAME"].to_s + env["PATH_INFO"].to_s
env["SCRIPT_NAME"] = ""
@app.call(env)
end
end
Of course, use this only when your app runs at "/".
Since lighttpd 1.4.23, you also can use the "fix-root-scriptname" flag
in fastcgi.server.
= Known conflicts regarding parameter parsing
* Many users have differing opinions about parameter parsing. The current
parameter parsers in Rack are based on a combination of the HTTP and CGI
specs, and are intended to round-trip encoding and decoding. There are some
choices that may be viewed as deficiencies, specifically:
- Rack does not create implicit arrays for multiple instances of a parameter
- Rack returns nil when a value is not given
- Rack does not support multi-type keys in parameters
These issues or choices, will not be fixed before 2.0, if at all. They are
very major breaking changes. Users are free to write alternative parameter
parsers, and their own Request and Response wrappers. Moreover, users are
encouraged to do so.
PK ! /A /A
HISTORY.mdnu [ Fri Jun 19 07:14:50 2015 Matthew Draper
* Work around a Rails incompatibility in our private API
Fri Jun 12 11:37:41 2015 Aaron Patterson
* Prevent extremely deep parameters from being parsed. CVE-2015-3225
### December 18th, Thirty sixth public release 1.6.0
### February 7th, Thirty fifth public release 1.5.2
- Fix CVE-2013-0263, timing attack against Rack::Session::Cookie
- Fix CVE-2013-0262, symlink path traversal in Rack::File
- Add various methods to Session for enhanced Rails compatibility
- Request#trusted_proxy? now only matches whole stirngs
- Add JSON cookie coder, to be default in Rack 1.6+ due to security concerns
- URLMap host matching in environments that don't set the Host header fixed
- Fix a race condition that could result in overwritten pidfiles
- Various documentation additions
### February 7th, Thirty fifth public release 1.4.5
- Fix CVE-2013-0263, timing attack against Rack::Session::Cookie
- Fix CVE-2013-0262, symlink path traversal in Rack::File
### February 7th, Thirty fifth public release 1.1.6, 1.2.8, 1.3.10
- Fix CVE-2013-0263, timing attack against Rack::Session::Cookie
### January 28th, 2013: Thirty fourth public release 1.5.1
- Rack::Lint check_hijack now conforms to other parts of SPEC
- Added hash-like methods to Abstract::ID::SessionHash for compatibility
- Various documentation corrections
### January 21st, 2013: Thirty third public release 1.5.0
- Introduced hijack SPEC, for before-response and after-response hijacking
- SessionHash is no longer a Hash subclass
- Rack::File cache_control parameter is removed, in place of headers options
- Rack::Auth::AbstractRequest#scheme now yields strings, not symbols
- Rack::Utils cookie functions now format expires in RFC 2822 format
- Rack::File now has a default mime type
- rackup -b 'run Rack::File.new(".")', option provides command line configs
- Rack::Deflater will no longer double encode bodies
- Rack::Mime#match? provides convenience for Accept header matching
- Rack::Utils#q_values provides splitting for Accept headers
- Rack::Utils#best_q_match provides a helper for Accept headers
- Rack::Handler.pick provides convenience for finding available servers
- Puma added to the list of default servers (preferred over Webrick)
- Various middleware now correctly close body when replacing it
- Rack::Request#params is no longer persistent with only GET params
- Rack::Request#update_param and #delete_param provide persistent operations
- Rack::Request#trusted_proxy? now returns true for local unix sockets
- Rack::Response no longer forces Content-Types
- Rack::Sendfile provides local mapping configuration options
- Rack::Utils#rfc2109 provides old netscape style time output
- Updated HTTP status codes
- Ruby 1.8.6 likely no longer passes tests, and is no longer fully supported
### January 13th, 2013: Thirty second public release 1.4.4, 1.3.9, 1.2.7, 1.1.5
- [SEC] Rack::Auth::AbstractRequest no longer symbolizes arbitrary strings
- Fixed erroneous test case in the 1.3.x series
### January 7th, 2013: Thirty first public release 1.4.3
- Security: Prevent unbounded reads in large multipart boundaries
### January 7th, 2013: Thirtieth public release 1.3.8
- Security: Prevent unbounded reads in large multipart boundaries
### January 6th, 2013: Twenty ninth public release 1.4.2
- Add warnings when users do not provide a session secret
- Fix parsing performance for unquoted filenames
- Updated URI backports
- Fix URI backport version matching, and silence constant warnings
- Correct parameter parsing with empty values
- Correct rackup '-I' flag, to allow multiple uses
- Correct rackup pidfile handling
- Report rackup line numbers correctly
- Fix request loops caused by non-stale nonces with time limits
- Fix reloader on Windows
- Prevent infinite recursions from Response#to_ary
- Various middleware better conforms to the body close specification
- Updated language for the body close specification
- Additional notes regarding ECMA escape compatibility issues
- Fix the parsing of multiple ranges in range headers
- Prevent errors from empty parameter keys
- Added PATCH verb to Rack::Request
- Various documentation updates
- Fix session merge semantics (fixes rack-test)
- Rack::Static :index can now handle multiple directories
- All tests now utilize Rack::Lint (special thanks to Lars Gierth)
- Rack::File cache_control parameter is now deprecated, and removed by 1.5
- Correct Rack::Directory script name escaping
- Rack::Static supports header rules for sophisticated configurations
- Multipart parsing now works without a Content-Length header
- New logos courtesy of Zachary Scott!
- Rack::BodyProxy now explicitly defines #each, useful for C extensions
- Cookies that are not URI escaped no longer cause exceptions
### January 6th, 2013: Twenty eighth public release 1.3.7
- Add warnings when users do not provide a session secret
- Fix parsing performance for unquoted filenames
- Updated URI backports
- Fix URI backport version matching, and silence constant warnings
- Correct parameter parsing with empty values
- Correct rackup '-I' flag, to allow multiple uses
- Correct rackup pidfile handling
- Report rackup line numbers correctly
- Fix request loops caused by non-stale nonces with time limits
- Fix reloader on Windows
- Prevent infinite recursions from Response#to_ary
- Various middleware better conforms to the body close specification
- Updated language for the body close specification
- Additional notes regarding ECMA escape compatibility issues
- Fix the parsing of multiple ranges in range headers
### January 6th, 2013: Twenty seventh public release 1.2.6
- Add warnings when users do not provide a session secret
- Fix parsing performance for unquoted filenames
### January 6th, 2013: Twenty sixth public release 1.1.4
- Add warnings when users do not provide a session secret
### January 22nd, 2012: Twenty fifth public release 1.4.1
- Alter the keyspace limit calculations to reduce issues with nested params
- Add a workaround for multipart parsing where files contain unescaped "%"
- Added Rack::Response::Helpers#method_not_allowed? (code 405)
- Rack::File now returns 404 for illegal directory traversals
- Rack::File now returns 405 for illegal methods (non HEAD/GET)
- Rack::Cascade now catches 405 by default, as well as 404
- Cookies missing '--' no longer cause an exception to be raised
- Various style changes and documentation spelling errors
- Rack::BodyProxy always ensures to execute its block
- Additional test coverage around cookies and secrets
- Rack::Session::Cookie can now be supplied either secret or old_secret
- Tests are no longer dependent on set order
- Rack::Static no longer defaults to serving index files
- Rack.release was fixed
### December 28th, 2011: Twenty fourth public release 1.4.0
- Ruby 1.8.6 support has officially been dropped. Not all tests pass.
- Raise sane error messages for broken config.ru
- Allow combining run and map in a config.ru
- Rack::ContentType will not set Content-Type for responses without a body
- Status code 205 does not send a response body
- Rack::Response::Helpers will not rely on instance variables
- Rack::Utils.build_query no longer outputs '=' for nil query values
- Various mime types added
- Rack::MockRequest now supports HEAD
- Rack::Directory now supports files that contain RFC3986 reserved chars
- Rack::File now only supports GET and HEAD requests
- Rack::Server#start now passes the block to Rack::Handler::#run
- Rack::Static now supports an index option
- Added the Teapot status code
- rackup now defaults to Thin instead of Mongrel (if installed)
- Support added for HTTP_X_FORWARDED_SCHEME
- Numerous bug fixes, including many fixes for new and alternate rubies
### December 28th, 2011: Twenty first public release: 1.1.3.
- Security fix. http://www.ocert.org/advisories/ocert-2011-003.html
Further information here: http://jruby.org/2011/12/27/jruby-1-6-5-1
### October 17, 2011: Twentieth public release 1.3.5
- Fix annoying warnings caused by the backport in 1.3.4
### October 1, 2011: Nineteenth public release 1.3.4
- Backport security fix from 1.9.3, also fixes some roundtrip issues in URI
- Small documentation update
- Fix an issue where BodyProxy could cause an infinite recursion
- Add some supporting files for travis-ci
### September 16, 2011: Eighteenth public release 1.2.4
- Fix a bug with MRI regex engine to prevent XSS by malformed unicode
### September 16, 2011: Seventeenth public release 1.3.3
- Fix bug with broken query parameters in Rack::ShowExceptions
- Rack::Request#cookies no longer swallows exceptions on broken input
- Prevents XSS attacks enabled by bug in Ruby 1.8's regexp engine
- Rack::ConditionalGet handles broken If-Modified-Since helpers
### July 16, 2011: Sixteenth public release 1.3.2
- Fix for Rails and rack-test, Rack::Utils#escape calls to_s
### July 13, 2011: Fifteenth public release 1.3.1
- Fix 1.9.1 support
- Fix JRuby support
- Properly handle $KCODE in Rack::Utils.escape
- Make method_missing/respond_to behavior consistent for Rack::Lock,
Rack::Auth::Digest::Request and Rack::Multipart::UploadedFile
- Reenable passing rack.session to session middleware
- Rack::CommonLogger handles streaming responses correctly
- Rack::MockResponse calls close on the body object
- Fix a DOS vector from MRI stdlib backport
### May 22nd, 2011: Fourteenth public release 1.2.3
- Pulled in relevant bug fixes from 1.3
- Fixed 1.8.6 support
### May 22nd, 2011: Thirteenth public release 1.3.0
- Various performance optimizations
- Various multipart fixes
- Various multipart refactors
- Infinite loop fix for multipart
- Test coverage for Rack::Server returns
- Allow files with '..', but not path components that are '..'
- rackup accepts handler-specific options on the command line
- Request#params no longer merges POST into GET (but returns the same)
- Use URI.encode_www_form_component instead. Use core methods for escaping.
- Allow multi-line comments in the config file
- Bug L#94 reported by Nikolai Lugovoi, query parameter unescaping.
- Rack::Response now deletes Content-Length when appropriate
- Rack::Deflater now supports streaming
- Improved Rack::Handler loading and searching
- Support for the PATCH verb
- env['rack.session.options'] now contains session options
- Cookies respect renew
- Session middleware uses SecureRandom.hex
### March 13th, 2011: Twelfth public release 1.2.2/1.1.2.
- Security fix in Rack::Auth::Digest::MD5: when authenticator
returned nil, permission was granted on empty password.
### June 15th, 2010: Eleventh public release 1.2.1.
- Make CGI handler rewindable
- Rename spec/ to test/ to not conflict with SPEC on lesser
operating systems
### June 13th, 2010: Tenth public release 1.2.0.
- Removed Camping adapter: Camping 2.0 supports Rack as-is
- Removed parsing of quoted values
- Add Request.trace? and Request.options?
- Add mime-type for .webm and .htc
- Fix HTTP_X_FORWARDED_FOR
- Various multipart fixes
- Switch test suite to bacon
### January 3rd, 2010: Ninth public release 1.1.0.
- Moved Auth::OpenID to rack-contrib.
- SPEC change that relaxes Lint slightly to allow subclasses of the
required types
- SPEC change to document rack.input binary mode in greator detail
- SPEC define optional rack.logger specification
- File servers support X-Cascade header
- Imported Config middleware
- Imported ETag middleware
- Imported Runtime middleware
- Imported Sendfile middleware
- New Logger and NullLogger middlewares
- Added mime type for .ogv and .manifest.
- Don't squeeze PATH_INFO slashes
- Use Content-Type to determine POST params parsing
- Update Rack::Utils::HTTP_STATUS_CODES hash
- Add status code lookup utility
- Response should call #to_i on the status
- Add Request#user_agent
- Request#host knows about forwared host
- Return an empty string for Request#host if HTTP_HOST and
SERVER_NAME are both missing
- Allow MockRequest to accept hash params
- Optimizations to HeaderHash
- Refactored rackup into Rack::Server
- Added Utils.build_nested_query to complement Utils.parse_nested_query
- Added Utils::Multipart.build_multipart to complement
Utils::Multipart.parse_multipart
- Extracted set and delete cookie helpers into Utils so they can be
used outside Response
- Extract parse_query and parse_multipart in Request so subclasses
can change their behavior
- Enforce binary encoding in RewindableInput
- Set correct external_encoding for handlers that don't use RewindableInput
### October 18th, 2009: Eighth public release 1.0.1.
- Bump remainder of rack.versions.
- Support the pure Ruby FCGI implementation.
- Fix for form names containing "=": split first then unescape components
- Fixes the handling of the filename parameter with semicolons in names.
- Add anchor to nested params parsing regexp to prevent stack overflows
- Use more compatible gzip write api instead of "<<".
- Make sure that Reloader doesn't break when executed via ruby -e
- Make sure WEBrick respects the :Host option
- Many Ruby 1.9 fixes.
### April 25th, 2009: Seventh public release 1.0.0.
- SPEC change: Rack::VERSION has been pushed to [1,0].
- SPEC change: header values must be Strings now, split on "\n".
- SPEC change: Content-Length can be missing, in this case chunked transfer
encoding is used.
- SPEC change: rack.input must be rewindable and support reading into
a buffer, wrap with Rack::RewindableInput if it isn't.
- SPEC change: rack.session is now specified.
- SPEC change: Bodies can now additionally respond to #to_path with
a filename to be served.
- NOTE: String bodies break in 1.9, use an Array consisting of a
single String instead.
- New middleware Rack::Lock.
- New middleware Rack::ContentType.
- Rack::Reloader has been rewritten.
- Major update to Rack::Auth::OpenID.
- Support for nested parameter parsing in Rack::Response.
- Support for redirects in Rack::Response.
- HttpOnly cookie support in Rack::Response.
- The Rakefile has been rewritten.
- Many bugfixes and small improvements.
### January 9th, 2009: Sixth public release 0.9.1.
- Fix directory traversal exploits in Rack::File and Rack::Directory.
### January 6th, 2009: Fifth public release 0.9.
- Rack is now managed by the Rack Core Team.
- Rack::Lint is stricter and follows the HTTP RFCs more closely.
- Added ConditionalGet middleware.
- Added ContentLength middleware.
- Added Deflater middleware.
- Added Head middleware.
- Added MethodOverride middleware.
- Rack::Mime now provides popular MIME-types and their extension.
- Mongrel Header now streams.
- Added Thin handler.
- Official support for swiftiplied Mongrel.
- Secure cookies.
- Made HeaderHash case-preserving.
- Many bugfixes and small improvements.
### August 21st, 2008: Fourth public release 0.4.
- New middleware, Rack::Deflater, by Christoffer Sawicki.
- OpenID authentication now needs ruby-openid 2.
- New Memcache sessions, by blink.
- Explicit EventedMongrel handler, by Joshua Peek
- Rack::Reloader is not loaded in rackup development mode.
- rackup can daemonize with -D.
- Many bugfixes, especially for pool sessions, URLMap, thread safety
and tempfile handling.
- Improved tests.
- Rack moved to Git.
### February 26th, 2008: Third public release 0.3.
- LiteSpeed handler, by Adrian Madrid.
- SCGI handler, by Jeremy Evans.
- Pool sessions, by blink.
- OpenID authentication, by blink.
- :Port and :File options for opening FastCGI sockets, by blink.
- Last-Modified HTTP header for Rack::File, by blink.
- Rack::Builder#use now accepts blocks, by Corey Jewett.
(See example/protectedlobster.ru)
- HTTP status 201 can contain a Content-Type and a body now.
- Many bugfixes, especially related to Cookie handling.
### May 16th, 2007: Second public release 0.2.
- HTTP Basic authentication.
- Cookie Sessions.
- Static file handler.
- Improved Rack::Request.
- Improved Rack::Response.
- Added Rack::ShowStatus, for better default error messages.
- Bug fixes in the Camping adapter.
- Removed Rails adapter, was too alpha.
### March 3rd, 2007: First public release 0.1.
PK ! p rack.gemspecnu [ Gem::Specification.new do |s|
s.name = "rack"
s.version = "1.6.4"
s.platform = Gem::Platform::RUBY
s.summary = "a modular Ruby webserver interface"
s.license = "MIT"
s.description = <<-EOF
Rack provides a minimal, modular and adaptable interface for developing
web applications in Ruby. By wrapping HTTP requests and responses in
the simplest way possible, it unifies and distills the API for web
servers, web frameworks, and software in between (the so-called
middleware) into a single method call.
Also see http://rack.github.io/.
EOF
s.files = Dir['{bin/*,contrib/*,example/*,lib/**/*,test/**/*}'] +
%w(COPYING KNOWN-ISSUES rack.gemspec Rakefile README.rdoc SPEC)
s.bindir = 'bin'
s.executables << 'rackup'
s.require_path = 'lib'
s.extra_rdoc_files = ['README.rdoc', 'KNOWN-ISSUES', 'HISTORY.md']
s.test_files = Dir['test/spec_*.rb']
s.author = 'Christian Neukirchen'
s.email = 'chneukirchen@gmail.com'
s.homepage = 'http://rack.github.io/'
s.rubyforge_project = 'rack'
s.add_development_dependency 'bacon'
s.add_development_dependency 'rake'
end
PK !
test/spec_showstatus.rbnu [ require 'rack/showstatus'
require 'rack/lint'
require 'rack/mock'
require 'rack/utils'
describe Rack::ShowStatus do
def show_status(app)
Rack::Lint.new Rack::ShowStatus.new(app)
end
should "provide a default status message" do
req = Rack::MockRequest.new(
show_status(lambda{|env|
[404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
}))
res = req.get("/", :lint => true)
res.should.be.not_found
res.should.be.not.empty
res["Content-Type"].should.equal("text/html")
res.should =~ /404/
res.should =~ /Not Found/
end
should "let the app provide additional information" do
req = Rack::MockRequest.new(
show_status(
lambda{|env|
env["rack.showstatus.detail"] = "gone too meta."
[404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
}))
res = req.get("/", :lint => true)
res.should.be.not_found
res.should.be.not.empty
res["Content-Type"].should.equal("text/html")
res.should =~ /404/
res.should =~ /Not Found/
res.should =~ /too meta/
end
should "escape error" do
detail = ""
req = Rack::MockRequest.new(
show_status(
lambda{|env|
env["rack.showstatus.detail"] = detail
[500, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
}))
res = req.get("/", :lint => true)
res.should.be.not.empty
res["Content-Type"].should.equal("text/html")
res.should =~ /500/
res.should.not.include detail
res.body.should.include Rack::Utils.escape_html(detail)
end
should "not replace existing messages" do
req = Rack::MockRequest.new(
show_status(
lambda{|env|
[404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
}))
res = req.get("/", :lint => true)
res.should.be.not_found
res.body.should == "foo!"
end
should "pass on original headers" do
headers = {"WWW-Authenticate" => "Basic blah"}
req = Rack::MockRequest.new(
show_status(lambda{|env| [401, headers, []] }))
res = req.get("/", :lint => true)
res["WWW-Authenticate"].should.equal("Basic blah")
end
should "replace existing messages if there is detail" do
req = Rack::MockRequest.new(
show_status(
lambda{|env|
env["rack.showstatus.detail"] = "gone too meta."
[404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
}))
res = req.get("/", :lint => true)
res.should.be.not_found
res.should.be.not.empty
res["Content-Type"].should.equal("text/html")
res["Content-Length"].should.not.equal("4")
res.should =~ /404/
res.should =~ /too meta/
res.body.should.not =~ /foo/
end
end
PK ! K test/spec_methodoverride.rbnu [ require 'stringio'
require 'rack/methodoverride'
require 'rack/mock'
describe Rack::MethodOverride do
def app
Rack::Lint.new(Rack::MethodOverride.new(lambda {|e|
[200, {"Content-Type" => "text/plain"}, []]
}))
end
should "not affect GET requests" do
env = Rack::MockRequest.env_for("/?_method=delete", :method => "GET")
app.call env
env["REQUEST_METHOD"].should.equal "GET"
end
should "modify REQUEST_METHOD for POST requests when _method parameter is set" do
env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=put")
app.call env
env["REQUEST_METHOD"].should.equal "PUT"
end
should "modify REQUEST_METHOD for POST requests when X-HTTP-Method-Override is set" do
env = Rack::MockRequest.env_for("/",
:method => "POST",
"HTTP_X_HTTP_METHOD_OVERRIDE" => "PATCH"
)
app.call env
env["REQUEST_METHOD"].should.equal "PATCH"
end
should "not modify REQUEST_METHOD if the method is unknown" do
env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=foo")
app.call env
env["REQUEST_METHOD"].should.equal "POST"
end
should "not modify REQUEST_METHOD when _method is nil" do
env = Rack::MockRequest.env_for("/", :method => "POST", :input => "foo=bar")
app.call env
env["REQUEST_METHOD"].should.equal "POST"
end
should "store the original REQUEST_METHOD prior to overriding" do
env = Rack::MockRequest.env_for("/",
:method => "POST",
:input => "_method=options")
app.call env
env["rack.methodoverride.original_method"].should.equal "POST"
end
should "not modify REQUEST_METHOD when given invalid multipart form data" do
input = < "multipart/form-data, boundary=AaB03x",
"CONTENT_LENGTH" => input.size.to_s,
:method => "POST", :input => input)
begin
app.call env
rescue EOFError
end
env["REQUEST_METHOD"].should.equal "POST"
end
should "not modify REQUEST_METHOD for POST requests when the params are unparseable" do
env = Rack::MockRequest.env_for("/", :method => "POST", :input => "(%bad-params%)")
app.call env
env["REQUEST_METHOD"].should.equal "POST"
end
end
PK ! ( test/spec_handler.rbnu [ require 'rack/handler'
class Rack::Handler::Lobster; end
class RockLobster; end
describe Rack::Handler do
it "has registered default handlers" do
Rack::Handler.get('cgi').should.equal Rack::Handler::CGI
Rack::Handler.get('webrick').should.equal Rack::Handler::WEBrick
begin
Rack::Handler.get('fastcgi').should.equal Rack::Handler::FastCGI
rescue LoadError
end
begin
Rack::Handler.get('mongrel').should.equal Rack::Handler::Mongrel
rescue LoadError
end
end
should "raise LoadError if handler doesn't exist" do
lambda {
Rack::Handler.get('boom')
}.should.raise(LoadError)
lambda {
Rack::Handler.get('Object')
}.should.raise(LoadError)
end
should "get unregistered, but already required, handler by name" do
Rack::Handler.get('Lobster').should.equal Rack::Handler::Lobster
end
should "register custom handler" do
Rack::Handler.register('rock_lobster', 'RockLobster')
Rack::Handler.get('rock_lobster').should.equal RockLobster
end
should "not need registration for properly coded handlers even if not already required" do
begin
$LOAD_PATH.push File.expand_path('../unregistered_handler', __FILE__)
Rack::Handler.get('Unregistered').should.equal Rack::Handler::Unregistered
lambda {
Rack::Handler.get('UnRegistered')
}.should.raise LoadError
Rack::Handler.get('UnregisteredLongOne').should.equal Rack::Handler::UnregisteredLongOne
ensure
$LOAD_PATH.delete File.expand_path('../unregistered_handler', __FILE__)
end
end
should "allow autoloaded handlers to be registered properly while being loaded" do
path = File.expand_path('../registering_handler', __FILE__)
begin
$LOAD_PATH.push path
Rack::Handler.get('registering_myself').should.equal Rack::Handler::RegisteringMyself
ensure
$LOAD_PATH.delete path
end
end
end
PK ! lM*( *( test/spec_deflater.rbnu [ require 'stringio'
require 'time' # for Time#httpdate
require 'rack/deflater'
require 'rack/lint'
require 'rack/mock'
require 'zlib'
describe Rack::Deflater do
def build_response(status, body, accept_encoding, options = {})
body = [body] if body.respond_to? :to_str
app = lambda do |env|
res = [status, options['response_headers'] || {}, body]
res[1]['Content-Type'] = 'text/plain' unless res[0] == 304
res
end
request = Rack::MockRequest.env_for('', (options['request_headers'] || {}).merge('HTTP_ACCEPT_ENCODING' => accept_encoding))
deflater = Rack::Lint.new Rack::Deflater.new(app, options['deflater_options'] || {})
deflater.call(request)
end
##
# Constructs response object and verifies if it yields right results
#
# [expected_status] expected response status, e.g. 200, 304
# [expected_body] expected response body
# [accept_encoing] what Accept-Encoding header to send and expect, e.g.
# 'deflate' - accepts and expects deflate encoding in response
# { 'gzip' => nil } - accepts gzip but expects no encoding in response
# [options] hash of request options, i.e.
# 'app_status' - what status dummy app should return (may be changed by deflater at some point)
# 'app_body' - what body dummy app should return (may be changed by deflater at some point)
# 'request_headers' - extra reqest headers to be sent
# 'response_headers' - extra response headers to be returned
# 'deflater_options' - options passed to deflater middleware
# [block] useful for doing some extra verification
def verify(expected_status, expected_body, accept_encoding, options = {}, &block)
accept_encoding, expected_encoding = if accept_encoding.kind_of?(Hash)
[accept_encoding.keys.first, accept_encoding.values.first]
else
[accept_encoding, accept_encoding.dup]
end
# build response
status, headers, body = build_response(
options['app_status'] || expected_status,
options['app_body'] || expected_body,
accept_encoding,
options
)
# verify status
status.should.equal(expected_status)
# verify body
unless options['skip_body_verify']
body_text = ''
body.each { |part| body_text << part }
deflated_body = case expected_encoding
when 'deflate'
inflater = Zlib::Inflate.new(-Zlib::MAX_WBITS)
inflater.inflate(body_text) << inflater.finish
when 'gzip'
io = StringIO.new(body_text)
gz = Zlib::GzipReader.new(io)
tmp = gz.read
gz.close
tmp
else
body_text
end
deflated_body.should.equal(expected_body)
end
# yield full response verification
yield(status, headers, body) if block_given?
end
should 'be able to deflate bodies that respond to each' do
app_body = Object.new
class << app_body; def each; yield('foo'); yield('bar'); end; end
verify(200, 'foobar', 'deflate', { 'app_body' => app_body }) do |status, headers, body|
headers.should.equal({
'Content-Encoding' => 'deflate',
'Vary' => 'Accept-Encoding',
'Content-Type' => 'text/plain'
})
end
end
should 'flush deflated chunks to the client as they become ready' do
app_body = Object.new
class << app_body; def each; yield('foo'); yield('bar'); end; end
verify(200, app_body, 'deflate', { 'skip_body_verify' => true }) do |status, headers, body|
headers.should.equal({
'Content-Encoding' => 'deflate',
'Vary' => 'Accept-Encoding',
'Content-Type' => 'text/plain'
})
buf = []
inflater = Zlib::Inflate.new(-Zlib::MAX_WBITS)
body.each { |part| buf << inflater.inflate(part) }
buf << inflater.finish
buf.delete_if { |part| part.empty? }.join.should.equal('foobar')
end
end
# TODO: This is really just a special case of the above...
should 'be able to deflate String bodies' do
verify(200, 'Hello world!', 'deflate') do |status, headers, body|
headers.should.equal({
'Content-Encoding' => 'deflate',
'Vary' => 'Accept-Encoding',
'Content-Type' => 'text/plain'
})
end
end
should 'be able to gzip bodies that respond to each' do
app_body = Object.new
class << app_body; def each; yield('foo'); yield('bar'); end; end
verify(200, 'foobar', 'gzip', { 'app_body' => app_body }) do |status, headers, body|
headers.should.equal({
'Content-Encoding' => 'gzip',
'Vary' => 'Accept-Encoding',
'Content-Type' => 'text/plain'
})
end
end
should 'flush gzipped chunks to the client as they become ready' do
app_body = Object.new
class << app_body; def each; yield('foo'); yield('bar'); end; end
verify(200, app_body, 'gzip', { 'skip_body_verify' => true }) do |status, headers, body|
headers.should.equal({
'Content-Encoding' => 'gzip',
'Vary' => 'Accept-Encoding',
'Content-Type' => 'text/plain'
})
buf = []
inflater = Zlib::Inflate.new(Zlib::MAX_WBITS + 32)
body.each { |part| buf << inflater.inflate(part) }
buf << inflater.finish
buf.delete_if { |part| part.empty? }.join.should.equal('foobar')
end
end
should 'be able to fallback to no deflation' do
verify(200, 'Hello world!', 'superzip') do |status, headers, body|
headers.should.equal({
'Vary' => 'Accept-Encoding',
'Content-Type' => 'text/plain'
})
end
end
should 'be able to skip when there is no response entity body' do
verify(304, '', { 'gzip' => nil }, { 'app_body' => [] }) do |status, headers, body|
headers.should.equal({})
end
end
should 'handle the lack of an acceptable encoding' do
app_body = 'Hello world!'
not_found_body1 = 'An acceptable encoding for the requested resource / could not be found.'
not_found_body2 = 'An acceptable encoding for the requested resource /foo/bar could not be found.'
options1 = {
'app_status' => 200,
'app_body' => app_body,
'request_headers' => {
'PATH_INFO' => '/'
}
}
options2 = {
'app_status' => 200,
'app_body' => app_body,
'request_headers' => {
'PATH_INFO' => '/foo/bar'
}
}
verify(406, not_found_body1, 'identity;q=0', options1) do |status, headers, body|
headers.should.equal({
'Content-Type' => 'text/plain',
'Content-Length' => not_found_body1.length.to_s
})
end
verify(406, not_found_body2, 'identity;q=0', options2) do |status, headers, body|
headers.should.equal({
'Content-Type' => 'text/plain',
'Content-Length' => not_found_body2.length.to_s
})
end
end
should 'handle gzip response with Last-Modified header' do
last_modified = Time.now.httpdate
options = {
'response_headers' => {
'Content-Type' => 'text/plain',
'Last-Modified' => last_modified
}
}
verify(200, 'Hello World!', 'gzip', options) do |status, headers, body|
headers.should.equal({
'Content-Encoding' => 'gzip',
'Vary' => 'Accept-Encoding',
'Last-Modified' => last_modified,
'Content-Type' => 'text/plain'
})
end
end
should 'do nothing when no-transform Cache-Control directive present' do
options = {
'response_headers' => {
'Content-Type' => 'text/plain',
'Cache-Control' => 'no-transform'
}
}
verify(200, 'Hello World!', { 'gzip' => nil }, options) do |status, headers, body|
headers.should.not.include 'Content-Encoding'
end
end
should 'do nothing when Content-Encoding already present' do
options = {
'response_headers' => {
'Content-Type' => 'text/plain',
'Content-Encoding' => 'gzip'
}
}
verify(200, 'Hello World!', { 'gzip' => nil }, options)
end
should 'deflate when Content-Encoding is identity' do
options = {
'response_headers' => {
'Content-Type' => 'text/plain',
'Content-Encoding' => 'identity'
}
}
verify(200, 'Hello World!', 'deflate', options)
end
should "deflate if content-type matches :include" do
options = {
'response_headers' => {
'Content-Type' => 'text/plain'
},
'deflater_options' => {
:include => %w(text/plain)
}
}
verify(200, 'Hello World!', 'gzip', options)
end
should "deflate if content-type is included it :include" do
options = {
'response_headers' => {
'Content-Type' => 'text/plain; charset=us-ascii'
},
'deflater_options' => {
:include => %w(text/plain)
}
}
verify(200, 'Hello World!', 'gzip', options)
end
should "not deflate if content-type is not set but given in :include" do
options = {
'deflater_options' => {
:include => %w(text/plain)
}
}
verify(304, 'Hello World!', { 'gzip' => nil }, options)
end
should "not deflate if content-type do not match :include" do
options = {
'response_headers' => {
'Content-Type' => 'text/plain'
},
'deflater_options' => {
:include => %w(text/json)
}
}
verify(200, 'Hello World!', { 'gzip' => nil }, options)
end
should "deflate response if :if lambda evaluates to true" do
options = {
'deflater_options' => {
:if => lambda { |env, status, headers, body| true }
}
}
verify(200, 'Hello World!', 'deflate', options)
end
should "not deflate if :if lambda evaluates to false" do
options = {
'deflater_options' => {
:if => lambda { |env, status, headers, body| false }
}
}
verify(200, 'Hello World!', { 'gzip' => nil }, options)
end
should "check for Content-Length via :if" do
body = 'Hello World!'
body_len = body.length
options = {
'response_headers' => {
'Content-Length' => body_len.to_s
},
'deflater_options' => {
:if => lambda { |env, status, headers, body|
headers['Content-Length'].to_i >= body_len
}
}
}
verify(200, body, 'gzip', options)
end
end
PK ! CgR R test/spec_fastcgi.rbnu [ begin
require File.expand_path('../testrequest', __FILE__)
require 'rack/handler/fastcgi'
describe Rack::Handler::FastCGI do
extend TestRequest::Helpers
@host = '127.0.0.1'
@port = 9203
if `which lighttpd` && !$?.success?
raise "lighttpd not found"
end
# Keep this first.
$pid = fork {
ENV['RACK_ENV'] = 'deployment'
ENV['RUBYLIB'] = [
File.expand_path('../../lib', __FILE__),
ENV['RUBYLIB'],
].compact.join(':')
Dir.chdir(File.expand_path("../cgi", __FILE__)) do
exec "lighttpd -D -f lighttpd.conf"
end
}
should "respond" do
sleep 1
GET("/test")
response.should.not.be.nil
end
should "respond via rackup server" do
GET("/sample_rackup.ru")
status.should.equal 200
end
should "be a lighttpd" do
GET("/test.fcgi")
status.should.equal 200
response["SERVER_SOFTWARE"].should =~ /lighttpd/
response["HTTP_VERSION"].should.equal "HTTP/1.1"
response["SERVER_PROTOCOL"].should.equal "HTTP/1.1"
response["SERVER_PORT"].should.equal @port.to_s
response["SERVER_NAME"].should.equal @host
end
should "have rack headers" do
GET("/test.fcgi")
response["rack.version"].should.equal [1,3]
response["rack.multithread"].should.be.false
response["rack.multiprocess"].should.be.true
response["rack.run_once"].should.be.false
end
should "have CGI headers on GET" do
GET("/test.fcgi")
response["REQUEST_METHOD"].should.equal "GET"
response["SCRIPT_NAME"].should.equal "/test.fcgi"
response["REQUEST_PATH"].should.equal "/"
response["PATH_INFO"].should.equal ""
response["QUERY_STRING"].should.equal ""
response["test.postdata"].should.equal ""
GET("/test.fcgi/foo?quux=1")
response["REQUEST_METHOD"].should.equal "GET"
response["SCRIPT_NAME"].should.equal "/test.fcgi"
response["REQUEST_PATH"].should.equal "/"
response["PATH_INFO"].should.equal "/foo"
response["QUERY_STRING"].should.equal "quux=1"
end
should "have CGI headers on POST" do
POST("/test.fcgi", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
status.should.equal 200
response["REQUEST_METHOD"].should.equal "POST"
response["SCRIPT_NAME"].should.equal "/test.fcgi"
response["REQUEST_PATH"].should.equal "/"
response["QUERY_STRING"].should.equal ""
response["HTTP_X_TEST_HEADER"].should.equal "42"
response["test.postdata"].should.equal "rack-form-data=23"
end
should "support HTTP auth" do
GET("/test.fcgi", {:user => "ruth", :passwd => "secret"})
response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ="
end
should "set status" do
GET("/test.fcgi?secret")
status.should.equal 403
response["rack.url_scheme"].should.equal "http"
end
# Keep this last.
should "shutdown" do
Process.kill 15, $pid
Process.wait($pid).should.equal $pid
end
end
rescue RuntimeError
$stderr.puts "Skipping Rack::Handler::FastCGI tests (lighttpd is required). Install lighttpd and try again."
rescue LoadError
$stderr.puts "Skipping Rack::Handler::FastCGI tests (FCGI is required). `gem install fcgi` and try again."
end
PK ! TTBR R test/builder/comment.runu [ =begin
=end
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['OK']] }
PK ! y^K K test/builder/options.runu [ #\ -d
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['OK']] }
PK ! â.b b test/builder/anything.rbnu [ class Anything
def self.call(env)
[200, {'Content-Type' => 'text/plain'}, ['OK']]
end
end
PK ! ǭM M test/builder/line.runu [ run lambda{ |env| [200, {'Content-Type' => 'text/plain'}, [__LINE__.to_s]] }
PK ! ga$y y test/builder/end.runu [ run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['OK']] }
__END__
Should not be evaluated
Neither should
This
PK ! = test/spec_builder.rbnu [ require 'rack/builder'
require 'rack/lint'
require 'rack/mock'
require 'rack/showexceptions'
require 'rack/urlmap'
class NothingMiddleware
def initialize(app)
@app = app
end
def call(env)
@@env = env
response = @app.call(env)
response
end
def self.env
@@env
end
end
describe Rack::Builder do
def builder(&block)
Rack::Lint.new Rack::Builder.new(&block)
end
def builder_to_app(&block)
Rack::Lint.new Rack::Builder.new(&block).to_app
end
it "supports mapping" do
app = builder_to_app do
map '/' do |outer_env|
run lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, ['root']] }
end
map '/sub' do
run lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, ['sub']] }
end
end
Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'root'
Rack::MockRequest.new(app).get("/sub").body.to_s.should.equal 'sub'
end
it "doesn't dupe env even when mapping" do
app = builder_to_app do
use NothingMiddleware
map '/' do |outer_env|
run lambda { |inner_env|
inner_env['new_key'] = 'new_value'
[200, {"Content-Type" => "text/plain"}, ['root']]
}
end
end
Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'root'
NothingMiddleware.env['new_key'].should.equal 'new_value'
end
it "chains apps by default" do
app = builder_to_app do
use Rack::ShowExceptions
run lambda { |env| raise "bzzzt" }
end
Rack::MockRequest.new(app).get("/").should.be.server_error
Rack::MockRequest.new(app).get("/").should.be.server_error
Rack::MockRequest.new(app).get("/").should.be.server_error
end
it "has implicit #to_app" do
app = builder do
use Rack::ShowExceptions
run lambda { |env| raise "bzzzt" }
end
Rack::MockRequest.new(app).get("/").should.be.server_error
Rack::MockRequest.new(app).get("/").should.be.server_error
Rack::MockRequest.new(app).get("/").should.be.server_error
end
it "supports blocks on use" do
app = builder do
use Rack::ShowExceptions
use Rack::Auth::Basic do |username, password|
'secret' == password
end
run lambda { |env| [200, {"Content-Type" => "text/plain"}, ['Hi Boss']] }
end
response = Rack::MockRequest.new(app).get("/")
response.should.be.client_error
response.status.should.equal 401
# with auth...
response = Rack::MockRequest.new(app).get("/",
'HTTP_AUTHORIZATION' => 'Basic ' + ["joe:secret"].pack("m*"))
response.status.should.equal 200
response.body.to_s.should.equal 'Hi Boss'
end
it "has explicit #to_app" do
app = builder do
use Rack::ShowExceptions
run lambda { |env| raise "bzzzt" }
end
Rack::MockRequest.new(app).get("/").should.be.server_error
Rack::MockRequest.new(app).get("/").should.be.server_error
Rack::MockRequest.new(app).get("/").should.be.server_error
end
it "can mix map and run for endpoints" do
app = builder do
map '/sub' do
run lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, ['sub']] }
end
run lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, ['root']] }
end
Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'root'
Rack::MockRequest.new(app).get("/sub").body.to_s.should.equal 'sub'
end
it "accepts middleware-only map blocks" do
app = builder do
map('/foo') { use Rack::ShowExceptions }
run lambda { |env| raise "bzzzt" }
end
proc { Rack::MockRequest.new(app).get("/") }.should.raise(RuntimeError)
Rack::MockRequest.new(app).get("/foo").should.be.server_error
end
it "yields the generated app to a block for warmup" do
warmed_up_app = nil
app = Rack::Builder.new do
warmup { |a| warmed_up_app = a }
run lambda { |env| [200, {}, []] }
end.to_app
warmed_up_app.should.equal app
end
should "initialize apps once" do
app = builder do
class AppClass
def initialize
@called = 0
end
def call(env)
raise "bzzzt" if @called > 0
@called += 1
[200, {'Content-Type' => 'text/plain'}, ['OK']]
end
end
use Rack::ShowExceptions
run AppClass.new
end
Rack::MockRequest.new(app).get("/").status.should.equal 200
Rack::MockRequest.new(app).get("/").should.be.server_error
end
it "allows use after run" do
app = builder do
run lambda { |env| raise "bzzzt" }
use Rack::ShowExceptions
end
Rack::MockRequest.new(app).get("/").should.be.server_error
Rack::MockRequest.new(app).get("/").should.be.server_error
Rack::MockRequest.new(app).get("/").should.be.server_error
end
it 'complains about a missing run' do
proc do
Rack::Lint.new Rack::Builder.app { use Rack::ShowExceptions }
end.should.raise(RuntimeError)
end
describe "parse_file" do
def config_file(name)
File.join(File.dirname(__FILE__), 'builder', name)
end
it "parses commented options" do
app, options = Rack::Builder.parse_file config_file('options.ru')
options[:debug].should.be.true
Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'OK'
end
it "removes __END__ before evaluating app" do
app, _ = Rack::Builder.parse_file config_file('end.ru')
Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'OK'
end
it "supports multi-line comments" do
lambda {
Rack::Builder.parse_file config_file('comment.ru')
}.should.not.raise(SyntaxError)
end
it "requires anything not ending in .ru" do
$: << File.dirname(__FILE__)
app, * = Rack::Builder.parse_file 'builder/anything'
Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'OK'
$:.pop
end
it "sets __LINE__ correctly" do
app, _ = Rack::Builder.parse_file config_file('line.ru')
Rack::MockRequest.new(app).get("/").body.to_s.should.equal '1'
end
end
describe 'new_from_string' do
it "builds a rack app from string" do
app, = Rack::Builder.new_from_string "run lambda{|env| [200, {'Content-Type' => 'text/plane'}, ['OK']] }"
Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'OK'
end
end
end
PK ! %i i test/spec_static.rbnu [ require 'rack/static'
require 'rack/lint'
require 'rack/mock'
class DummyApp
def call(env)
[200, {"Content-Type" => "text/plain"}, ["Hello World"]]
end
end
describe Rack::Static do
def static(app, *args)
Rack::Lint.new Rack::Static.new(app, *args)
end
root = File.expand_path(File.dirname(__FILE__))
OPTIONS = {:urls => ["/cgi"], :root => root}
STATIC_OPTIONS = {:urls => [""], :root => "#{root}/static", :index => 'index.html'}
HASH_OPTIONS = {:urls => {"/cgi/sekret" => 'cgi/test'}, :root => root}
@request = Rack::MockRequest.new(static(DummyApp.new, OPTIONS))
@static_request = Rack::MockRequest.new(static(DummyApp.new, STATIC_OPTIONS))
@hash_request = Rack::MockRequest.new(static(DummyApp.new, HASH_OPTIONS))
it "serves files" do
res = @request.get("/cgi/test")
res.should.be.ok
res.body.should =~ /ruby/
end
it "404s if url root is known but it can't find the file" do
res = @request.get("/cgi/foo")
res.should.be.not_found
end
it "calls down the chain if url root is not known" do
res = @request.get("/something/else")
res.should.be.ok
res.body.should == "Hello World"
end
it "calls index file when requesting root in the given folder" do
res = @static_request.get("/")
res.should.be.ok
res.body.should =~ /index!/
res = @static_request.get("/other/")
res.should.be.not_found
res = @static_request.get("/another/")
res.should.be.ok
res.body.should =~ /another index!/
end
it "doesn't call index file if :index option was omitted" do
res = @request.get("/")
res.body.should == "Hello World"
end
it "serves hidden files" do
res = @hash_request.get("/cgi/sekret")
res.should.be.ok
res.body.should =~ /ruby/
end
it "calls down the chain if the URI is not specified" do
res = @hash_request.get("/something/else")
res.should.be.ok
res.body.should == "Hello World"
end
it "supports serving fixed cache-control (legacy option)" do
opts = OPTIONS.merge(:cache_control => 'public')
request = Rack::MockRequest.new(static(DummyApp.new, opts))
res = request.get("/cgi/test")
res.should.be.ok
res.headers['Cache-Control'].should == 'public'
end
HEADER_OPTIONS = {:urls => ["/cgi"], :root => root, :header_rules => [
[:all, {'Cache-Control' => 'public, max-age=100'}],
[:fonts, {'Cache-Control' => 'public, max-age=200'}],
[%w(png jpg), {'Cache-Control' => 'public, max-age=300'}],
['/cgi/assets/folder/', {'Cache-Control' => 'public, max-age=400'}],
['cgi/assets/javascripts', {'Cache-Control' => 'public, max-age=500'}],
[/\.(css|erb)\z/, {'Cache-Control' => 'public, max-age=600'}]
]}
@header_request = Rack::MockRequest.new(static(DummyApp.new, HEADER_OPTIONS))
it "supports header rule :all" do
# Headers for all files via :all shortcut
res = @header_request.get('/cgi/assets/index.html')
res.should.be.ok
res.headers['Cache-Control'].should == 'public, max-age=100'
end
it "supports header rule :fonts" do
# Headers for web fonts via :fonts shortcut
res = @header_request.get('/cgi/assets/fonts/font.eot')
res.should.be.ok
res.headers['Cache-Control'].should == 'public, max-age=200'
end
it "supports file extension header rules provided as an Array" do
# Headers for file extensions via array
res = @header_request.get('/cgi/assets/images/image.png')
res.should.be.ok
res.headers['Cache-Control'].should == 'public, max-age=300'
end
it "supports folder rules provided as a String" do
# Headers for files in folder via string
res = @header_request.get('/cgi/assets/folder/test.js')
res.should.be.ok
res.headers['Cache-Control'].should == 'public, max-age=400'
end
it "supports folder header rules provided as a String not starting with a slash" do
res = @header_request.get('/cgi/assets/javascripts/app.js')
res.should.be.ok
res.headers['Cache-Control'].should == 'public, max-age=500'
end
it "supports flexible header rules provided as Regexp" do
# Flexible Headers via Regexp
res = @header_request.get('/cgi/assets/stylesheets/app.css')
res.should.be.ok
res.headers['Cache-Control'].should == 'public, max-age=600'
end
it "prioritizes header rules over fixed cache-control setting (legacy option)" do
opts = OPTIONS.merge(
:cache_control => 'public, max-age=24',
:header_rules => [
[:all, {'Cache-Control' => 'public, max-age=42'}]
])
request = Rack::MockRequest.new(static(DummyApp.new, opts))
res = request.get("/cgi/test")
res.should.be.ok
res.headers['Cache-Control'].should == 'public, max-age=42'
end
end
PK ! FN N test/cgi/sample_rackup.runu ȯ # -*- ruby -*-
require '../testrequest'
run Rack::Lint.new(TestRequest.new)
PK ! <4` ` test/cgi/test.runu ȯ #!../../bin/rackup
# -*- ruby -*-
require '../testrequest'
run Rack::Lint.new(TestRequest.new)
PK ! &k ! test/cgi/test+directory/test+filenu [ this file has plusses!
PK ! x
test/cgi/testnu ȯ #!/usr/bin/env ruby
# -*- ruby -*-
$: << File.join(File.dirname(__FILE__), "..", "..", "lib")
require 'rack'
require '../testrequest'
Rack::Handler::CGI.run(Rack::Lint.new(TestRequest.new))
PK ! l~1 1 test/cgi/lighttpd.errorsnu [ 2015-06-16 14:11:43: (log.c.164) server started
PK ! test/cgi/test.fcginu ȯ #!/usr/bin/env ruby
# -*- ruby -*-
$:.unshift '../../lib'
require 'rack'
require '../testrequest'
Rack::Handler::FastCGI.run(Rack::Lint.new(TestRequest.new))
PK ! ?z] ] test/cgi/rackup_stub.rbnu ȯ #!/usr/bin/env ruby
# -*- ruby -*-
$:.unshift '../../lib'
require 'rack'
Rack::Server.start
PK ! XHi test/cgi/lighttpd.confnu ȯ server.modules = ("mod_fastcgi", "mod_cgi")
server.document-root = "."
server.errorlog = var.CWD + "/lighttpd.errors"
server.port = 9203
server.bind = "127.0.0.1"
server.event-handler = "select"
cgi.assign = ("/test" => "",
# ".ru" => ""
)
fastcgi.server = (
"test.fcgi" => ("localhost" =>
("min-procs" => 1,
"socket" => "/tmp/rack-test-fcgi",
"bin-path" => "test.fcgi")),
"test.ru" => ("localhost" =>
("min-procs" => 1,
"socket" => "/tmp/rack-test-ru-fcgi",
"bin-path" => CWD + "/rackup_stub.rb test.ru")),
"sample_rackup.ru" => ("localhost" =>
("min-procs" => 1,
"socket" => "/tmp/rack-test-rackup-fcgi",
"bin-path" => CWD + "/rackup_stub.rb sample_rackup.ru")),
)
PK ! o^ test/cgi/assets/fonts/font.eotnu [ ### TestFile ###
PK ! o^ # test/cgi/assets/stylesheets/app.cssnu [ ### TestFile ###
PK ! o^ test/cgi/assets/index.htmlnu [ ### TestFile ###
PK ! o^ test/cgi/assets/folder/test.jsnu [ ### TestFile ###
PK ! o^ test/cgi/assets/images/image.pngnu [ ### TestFile ###
PK ! o^ " test/cgi/assets/javascripts/app.jsnu [ ### TestFile ###
PK ! 4 4 test/spec_content_length.rbnu [ require 'rack/content_length'
require 'rack/lint'
require 'rack/mock'
describe Rack::ContentLength do
def content_length(app)
Rack::Lint.new Rack::ContentLength.new(app)
end
def request
Rack::MockRequest.env_for
end
should "set Content-Length on Array bodies if none is set" do
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
response = content_length(app).call(request)
response[1]['Content-Length'].should.equal '13'
end
should "not set Content-Length on variable length bodies" do
body = lambda { "Hello World!" }
def body.each ; yield call ; end
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] }
response = content_length(app).call(request)
response[1]['Content-Length'].should.be.nil
end
should "not change Content-Length if it is already set" do
app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Content-Length' => '1'}, "Hello, World!"] }
response = content_length(app).call(request)
response[1]['Content-Length'].should.equal '1'
end
should "not set Content-Length on 304 responses" do
app = lambda { |env| [304, {}, []] }
response = content_length(app).call(request)
response[1]['Content-Length'].should.equal nil
end
should "not set Content-Length when Transfer-Encoding is chunked" do
app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Transfer-Encoding' => 'chunked'}, []] }
response = content_length(app).call(request)
response[1]['Content-Length'].should.equal nil
end
# Using "Connection: close" for this is fairly contended. It might be useful
# to have some other way to signal this.
#
# should "not force a Content-Length when Connection:close" do
# app = lambda { |env| [200, {'Connection' => 'close'}, []] }
# response = content_length(app).call({})
# response[1]['Content-Length'].should.equal nil
# end
should "close bodies that need to be closed" do
body = Struct.new(:body) do
attr_reader :closed
def each; body.join; end
def close; @closed = true; end
def to_ary; end
end.new(%w[one two three])
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] }
response = content_length(app).call(request)
body.closed.should.equal nil
response[2].close
body.closed.should.equal true
end
should "support single-execute bodies" do
body = Struct.new(:body) do
def each
yield body.shift until body.empty?
end
def to_ary; end
end.new(%w[one two three])
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] }
response = content_length(app).call(request)
expected = %w[one two three]
response[1]['Content-Length'].should.equal expected.join.size.to_s
response[2].to_enum.to_a.should.equal expected
end
end
PK ! test/spec_rewindable_input.rbnu [ require 'stringio'
require 'rack/rewindable_input'
shared "a rewindable IO object" do
before do
@rio = Rack::RewindableInput.new(@io)
end
should "be able to handle to read()" do
@rio.read.should.equal "hello world"
end
should "be able to handle to read(nil)" do
@rio.read(nil).should.equal "hello world"
end
should "be able to handle to read(length)" do
@rio.read(1).should.equal "h"
end
should "be able to handle to read(length, buffer)" do
buffer = ""
result = @rio.read(1, buffer)
result.should.equal "h"
result.object_id.should.equal buffer.object_id
end
should "be able to handle to read(nil, buffer)" do
buffer = ""
result = @rio.read(nil, buffer)
result.should.equal "hello world"
result.object_id.should.equal buffer.object_id
end
should "rewind to the beginning when #rewind is called" do
@rio.read(1)
@rio.rewind
@rio.read.should.equal "hello world"
end
should "be able to handle gets" do
@rio.gets.should == "hello world"
end
should "be able to handle each" do
array = []
@rio.each do |data|
array << data
end
array.should.equal(["hello world"])
end
should "not buffer into a Tempfile if no data has been read yet" do
@rio.instance_variable_get(:@rewindable_io).should.be.nil
end
should "buffer into a Tempfile when data has been consumed for the first time" do
@rio.read(1)
tempfile = @rio.instance_variable_get(:@rewindable_io)
tempfile.should.not.be.nil
@rio.read(1)
tempfile2 = @rio.instance_variable_get(:@rewindable_io)
tempfile2.path.should == tempfile.path
end
should "close the underlying tempfile upon calling #close" do
@rio.read(1)
tempfile = @rio.instance_variable_get(:@rewindable_io)
@rio.close
tempfile.should.be.closed
end
should "be possible to call #close when no data has been buffered yet" do
lambda{ @rio.close }.should.not.raise
end
should "be possible to call #close multiple times" do
lambda{
@rio.close
@rio.close
}.should.not.raise
end
@rio.close
@rio = nil
end
describe Rack::RewindableInput do
describe "given an IO object that is already rewindable" do
before do
@io = StringIO.new("hello world")
end
behaves_like "a rewindable IO object"
end
describe "given an IO object that is not rewindable" do
before do
@io = StringIO.new("hello world")
@io.instance_eval do
undef :rewind
end
end
behaves_like "a rewindable IO object"
end
describe "given an IO object whose rewind method raises Errno::ESPIPE" do
before do
@io = StringIO.new("hello world")
def @io.rewind
raise Errno::ESPIPE, "You can't rewind this!"
end
end
behaves_like "a rewindable IO object"
end
end
PK ! n n test/spec_logger.rbnu [ require 'stringio'
require 'rack/lint'
require 'rack/logger'
require 'rack/mock'
describe Rack::Logger do
app = lambda { |env|
log = env['rack.logger']
log.debug("Created logger")
log.info("Program started")
log.warn("Nothing to do!")
[200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]]
}
should "conform to Rack::Lint" do
errors = StringIO.new
a = Rack::Lint.new(Rack::Logger.new(app))
Rack::MockRequest.new(a).get('/', 'rack.errors' => errors)
errors.string.should.match(/INFO -- : Program started/)
errors.string.should.match(/WARN -- : Nothing to do/)
end
end
PK ! $hi
test/spec_showexceptions.rbnu [ require 'rack/showexceptions'
require 'rack/lint'
require 'rack/mock'
describe Rack::ShowExceptions do
def show_exceptions(app)
Rack::Lint.new Rack::ShowExceptions.new(app)
end
it "catches exceptions" do
res = nil
req = Rack::MockRequest.new(
show_exceptions(
lambda{|env| raise RuntimeError }
))
lambda{
res = req.get("/", "HTTP_ACCEPT" => "text/html")
}.should.not.raise
res.should.be.a.server_error
res.status.should.equal 500
res.should =~ /RuntimeError/
res.should =~ /ShowExceptions/
end
it "responds with HTML only to requests accepting HTML" do
res = nil
req = Rack::MockRequest.new(
show_exceptions(
lambda{|env| raise RuntimeError, "It was never supposed to work" }
))
[
# Serve text/html when the client accepts text/html
["text/html", ["/", {"HTTP_ACCEPT" => "text/html"}]],
["text/html", ["/", {"HTTP_ACCEPT" => "*/*"}]],
# Serve text/plain when the client does not accept text/html
["text/plain", ["/"]],
["text/plain", ["/", {"HTTP_ACCEPT" => "application/json"}]]
].each do |exmime, rargs|
lambda{
res = req.get(*rargs)
}.should.not.raise
res.should.be.a.server_error
res.status.should.equal 500
res.content_type.should.equal exmime
res.body.should.include "RuntimeError"
res.body.should.include "It was never supposed to work"
if exmime == "text/html"
res.body.should.include '