goliath 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of goliath might be problematic. Click here for more details.

Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -4
  3. data/goliath.gemspec +10 -7
  4. data/lib/goliath/api.rb +1 -1
  5. data/lib/goliath/rack/jsonp.rb +7 -2
  6. data/lib/goliath/rack/params.rb +3 -2
  7. data/lib/goliath/rack/validator.rb +1 -1
  8. data/lib/goliath/request.rb +2 -2
  9. data/lib/goliath/runner.rb +4 -3
  10. data/lib/goliath/server.rb +17 -2
  11. data/lib/goliath/test_helper_sse.rb +76 -0
  12. data/lib/goliath/validation/error.rb +4 -1
  13. data/lib/goliath/version.rb +1 -1
  14. data/spec/integration/early_abort_spec.rb +3 -3
  15. data/spec/integration/event_stream_spec.rb +50 -0
  16. data/spec/integration/exception_handling_spec.rb +202 -0
  17. data/spec/integration/jsonp_spec.rb +61 -10
  18. data/spec/integration/test_helper_spec.rb +1 -1
  19. data/spec/integration/valid_spec.rb +21 -1
  20. data/spec/unit/api_spec.rb +1 -1
  21. data/spec/unit/env_spec.rb +5 -5
  22. data/spec/unit/headers_spec.rb +2 -2
  23. data/spec/unit/rack/formatters/json_spec.rb +2 -2
  24. data/spec/unit/rack/formatters/xml_spec.rb +2 -2
  25. data/spec/unit/rack/formatters/yaml_spec.rb +2 -2
  26. data/spec/unit/rack/params_spec.rb +41 -6
  27. data/spec/unit/rack/validation/default_params_spec.rb +2 -2
  28. data/spec/unit/rack/validation/numeric_range_spec.rb +2 -2
  29. data/spec/unit/rack/validation/param_spec.rb +18 -18
  30. data/spec/unit/rack/validation/required_param_spec.rb +25 -25
  31. data/spec/unit/rack/validation/required_value_spec.rb +10 -10
  32. data/spec/unit/request_spec.rb +3 -3
  33. data/spec/unit/runner_spec.rb +1 -1
  34. data/spec/unit/server_spec.rb +4 -4
  35. metadata +135 -94
  36. data/examples/around.rb +0 -38
  37. data/examples/clone.rb +0 -26
  38. data/examples/router.rb +0 -15
  39. data/examples/test.rb +0 -31
  40. data/examples/upload.rb +0 -17
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $:<< '../lib' << 'lib'
3
-
4
- require 'goliath'
5
-
6
- class ApiValidationAroundware
7
- include Goliath::Rack::SimpleAroundware
8
- class InvalidApiKeyError < Goliath::Validation::BadRequestError; end
9
-
10
- def pre_process
11
- validate_api_key!
12
- env.logger.info "past api_key validation" #<-- this is output, then an empty response header & body as if it is just hanging...
13
- Goliath::Connection::AsyncResponse
14
- end
15
-
16
- def post_process
17
- [status, headers, body]
18
- end
19
-
20
- def validate_api_key!
21
- server_api_key = env['config']['server_api_key'].to_s
22
- if api_key != server_api_key
23
- raise InvalidApiKeyError
24
- end
25
- end
26
-
27
- # retreive the client's api_key
28
- def api_key
29
- env['HTTP_API_KEY'].to_s
30
- end
31
- end
32
-
33
- class AwesomeApiWithLogging < Goliath::API
34
- use Goliath::Rack::SimpleAroundwareFactory, ApiValidationAroundware
35
- def response(env)
36
- [200, {}, "Hello"]
37
- end
38
- end
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $:<< '../lib' << 'lib'
3
-
4
- require 'goliath'
5
-
6
- class RandomAPI2 < Goliath::API
7
- use Goliath::Rack::Params
8
- use Goliath::Rack::Validation::Param, :key => 'user'
9
-
10
- def response(env)
11
- [200, {}, "Hello 2!"]
12
- end
13
- end
14
-
15
- class Router < Goliath::API
16
- map '/', RandomAPI2
17
- end
18
-
19
- # class PlainApi < Goliath::API
20
- # use Goliath::Rack::Params
21
- # use Goliath::Rack::Validation::Param, :key => 'user'
22
-
23
- # def response(env)
24
- # [200, {}, "Hello 2!"]
25
- # end
26
- # end
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $:<< '../lib' << 'lib'
3
-
4
- require 'goliath'
5
- require 'test'
6
-
7
-
8
- class Router < Goliath::API
9
- get '/v1/app/:appid/binary/:key', RawFileApp
10
- put '/v1/app/:appid/binary/:key', RawFileApp
11
-
12
- not_found do
13
- run Proc.new { |env| [404, {"Content-Type" => "text/html"}, "not found"] }
14
- end
15
- end
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $:<< '../lib' << 'lib'
3
-
4
- require 'goliath'
5
-
6
- class RawFileApp < Goliath::API
7
- use Goliath::Rack::Params # parse & merge query and body parameters
8
- use Goliath::Rack::DefaultMimeType # cleanup accepted media types
9
- use Goliath::Rack::Formatters::JSON # JSON output formatter
10
- use Goliath::Rack::Render # auto-negotiate response format
11
-
12
- def response(env)
13
- p params
14
- p params['key2']
15
- p params[:key2]
16
- obj = {
17
- somekey: 'val',
18
- otherkey: 42
19
- }
20
- [200, { 'Content-Type' => 'application/json' }, obj]
21
- end
22
- end
23
-
24
- class Router < Goliath::API
25
- get '/v1/app/:appid/binary/:key', RawFileApp
26
- put '/v1/app/:appid/binary/:key', RawFileApp
27
-
28
- not_found do
29
- run Proc.new { |env| [404, {"Content-Type" => "text/html"}, "not found"] }
30
- end
31
- end
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $:<< '../lib' << 'lib'
3
-
4
- require 'goliath'
5
-
6
- class Upload < Goliath::API
7
-
8
- def on_headers(env, h)
9
- if h['Expect'] == '100-continue'
10
- env.stream_send "HTTP/1.1 100 Continue\r\n"
11
- end
12
- end
13
-
14
- def response(env)
15
- [200, {}, "oh hai"]
16
- end
17
- end