Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 66 lines (57 sloc) 1.881 kb
8a2cecc @chneukirchen Add a lobster
chneukirchen authored
1 require 'zlib'
2
7ade69b @chneukirchen Add some missing tests
chneukirchen authored
3 require 'rack/request'
4 require 'rack/response'
5
8a2cecc @chneukirchen Add a lobster
chneukirchen authored
6 module Rack
376fa1e @chneukirchen Add RDocs
chneukirchen authored
7 # Paste has a Pony, Rack has a Lobster!
8 class Lobster
9 LobsterString = Zlib::Inflate.inflate("eJx9kEEOwyAMBO99xd7MAcytUhPlJyj2
10 P6jy9i4k9EQyGAnBarEXeCBqSkntNXsi/ZCvC48zGQoZKikGrFMZvgS5ZHd+aGWVuWwhVF0
11 t1drVmiR42HcWNz5w3QanT+2gIvTVCiE1lm1Y0eU4JGmIIbaKwextKn8rvW+p5PIwFl8ZWJ
12 I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0])
8a2cecc @chneukirchen Add a lobster
chneukirchen authored
13
376fa1e @chneukirchen Add RDocs
chneukirchen authored
14 LambdaLobster = lambda { |env|
15 if env["QUERY_STRING"].include?("flip")
16 lobster = LobsterString.split("\n").
17 map { |line| line.ljust(42).reverse }.
18 join("\n")
19 href = "?"
20 else
21 lobster = LobsterString
22 href = "?flip"
23 end
230d62c @chneukirchen Fix trailing whitespace. Sigh.
chneukirchen authored
24
4a04950 @chneukirchen Make Rack::Lobster set Content-Length
chneukirchen authored
25 content = ["<title>Lobstericious!</title>",
26 "<pre>", lobster, "</pre>",
27 "<a href='#{href}'>flip!</a>"]
28 length = content.inject(0) { |a,e| a+e.size }.to_s
29 [200, {"Content-Type" => "text/html", "Content-Length" => length}, content]
376fa1e @chneukirchen Add RDocs
chneukirchen authored
30 }
230d62c @chneukirchen Fix trailing whitespace. Sigh.
chneukirchen authored
31
376fa1e @chneukirchen Add RDocs
chneukirchen authored
32 def call(env)
33 req = Request.new(env)
34 if req.GET["flip"] == "left"
35 lobster = LobsterString.split("\n").
36 map { |line| line.ljust(42).reverse }.
37 join("\n")
38 href = "?flip=right"
39 elsif req.GET["flip"] == "crash"
40 raise "Lobster crashed"
41 else
42 lobster = LobsterString
43 href = "?flip=left"
44 end
230d62c @chneukirchen Fix trailing whitespace. Sigh.
chneukirchen authored
45
4a04950 @chneukirchen Make Rack::Lobster set Content-Length
chneukirchen authored
46 res = Response.new
47 res.write "<title>Lobstericious!</title>"
48 res.write "<pre>"
49 res.write lobster
50 res.write "</pre>"
51 res.write "<p><a href='#{href}'>flip!</a></p>"
52 res.write "<p><a href='?flip=crash'>crash!</a></p>"
53 res.finish
8a2cecc @chneukirchen Add a lobster
chneukirchen authored
54 end
116f0ef @chneukirchen Remove trailing whitespace *sigh*
chneukirchen authored
55
376fa1e @chneukirchen Add RDocs
chneukirchen authored
56 end
8a2cecc @chneukirchen Add a lobster
chneukirchen authored
57 end
58
59 if $0 == __FILE__
60 require 'rack'
69f11f6 @chneukirchen Add Rack::ShowExceptions
chneukirchen authored
61 require 'rack/showexceptions'
62 Rack::Handler::WEBrick.run \
376fa1e @chneukirchen Add RDocs
chneukirchen authored
63 Rack::ShowExceptions.new(Rack::Lint.new(Rack::Lobster.new)),
ed4bba8 @chneukirchen Fix things that should have been fixed before the release *sigh*
chneukirchen authored
64 :Port => 9292
8a2cecc @chneukirchen Add a lobster
chneukirchen authored
65 end
Something went wrong with that request. Please try again.