-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
157 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
require_relative 'lib/rack/conform/server' | ||
run Rack::Conform::Server.new | ||
require_relative 'lib/rack/conform/application' | ||
run Rack::Conform::Application.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,7 @@ | |
group :test do | ||
gem "bake-test" | ||
gem "bake-test-external" | ||
|
||
# For local testing... | ||
gem "falcon" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# frozen_string_literal: true | ||
|
||
# Released under the MIT License. | ||
# Copyright, 2022, by Samuel Williams. | ||
|
||
require 'json' | ||
|
||
module Rack | ||
module Conform | ||
class Application | ||
def call(env) | ||
self.public_send(test_method_for(env), env) | ||
end | ||
|
||
def test(env) | ||
[200, {}, ["Hello World"]] | ||
end | ||
|
||
def test_status(env) | ||
status = env.fetch('HTTP_STATUS', 200) | ||
[status.to_i, {}, []] | ||
end | ||
|
||
def test_echo(env) | ||
[200, {}, env['rack.input']] | ||
end | ||
|
||
def test_cookies(env) | ||
cookies = JSON.parse(env['rack.input'].read) | ||
|
||
Rack::Response.new.tap do |response| | ||
cookies.each do |key, value| | ||
response.set_cookie(key, value) | ||
end | ||
end.to_a | ||
end | ||
|
||
def test_headers(env) | ||
headers = JSON.parse(env['rack.input'].read) | ||
|
||
Rack::Response.new.tap do |response| | ||
headers.each do |key, value| | ||
Array(value).each do |value| | ||
response.add_header(key, value) | ||
end | ||
end | ||
end.to_a | ||
end | ||
|
||
def test_streaming_hijack(env) | ||
if env['rack.hijack?'] | ||
callback = proc do |stream| | ||
stream.write "Hello World" | ||
stream.close | ||
end | ||
|
||
return [200, {'rack.hijack' => callback}, nil] | ||
else | ||
[404, {}, []] | ||
end | ||
end | ||
|
||
def test_streaming_body(env) | ||
if Rack::RELEASE >= "3.0" | ||
callback = proc do |stream| | ||
stream.write "Hello World" | ||
stream.close | ||
end | ||
|
||
return [200, {}, callback] | ||
else | ||
[404, {}, []] | ||
end | ||
end | ||
|
||
private | ||
|
||
def test_method_for(env) | ||
parts = env['PATH_INFO'].split('/') | ||
parts[0] = "test" | ||
|
||
return parts.join('_').to_sym | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters