Sha256: e2e4d4b50c75f878f5525f9ee367e613fb9c628755cb3d187faac8cdfe043dde
Contents?: true
Size: 1.44 KB
Versions: 2
Compression:
Stored size: 1.44 KB
Contents
#!/usr/bin/env ruby $:<< '../lib' << 'lib' # # Example of using the rack/deflater middleware to automatically GZIP your response # if the client indicated that it will accept gzipped data. # # Note that we're also using Rack::Rewrite to alter incoming request prior to it # being parsed by the Rack::Params middleware. This allows us to transparently # rewrite incoming requests before any processing is done on it. # # curl -s -H "Accept-Encoding: gzip,deflate" -H "Connection: close" localhost:9000?gziped=test | gunzip # require 'rack/deflater' require 'rack/rewrite' require 'goliath' require 'yajl' class Gziped < Goliath::API # if client requested, compress the response use ::Rack::Deflater # example of using rack rewriting to rewrite the param gziped to echo use ::Rack::Rewrite do rewrite %r{^(.*?)\??gziped=(.*)$}, lambda { |match, env| "#{match[1]}?echo=#{match[2]}" } end use Goliath::Rack::Params # parse & merge query and body parameters use Goliath::Rack::Formatters::JSON # JSON output formatter use Goliath::Rack::Render # auto-negotiate response format use Goliath::Rack::ValidationError # catch and render validation errors use Goliath::Rack::Validation::RequestMethod, %w(GET) # allow GET requests only use Goliath::Rack::Validation::RequiredParam, {:key => 'echo'} # must provide ?echo= query or body param def response(env) [200, {}, {response: env.params['echo']}] end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
goliath-0.9.1 | examples/gziped.rb |
goliath-0.9.0 | examples/gziped.rb |