karmi (owner)

Revisions

gist: 171002 Download_button fork
public
Public Clone URL: git://gist.github.com/171002.git
Embed All Files: show embed
http_accept_route_condition_in_sinatra.rb #
1
2
3
4
5
6
7
8
9
10
require 'rubygems'
require 'sinatra'
 
def accept(type)
  condition { type === request.accept.first }
end
 
get '/', :accept => 'application/xml' do
  "Welcome RESTafari"
end
test.sh #
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/env bash
 
echo "OK:"
 
curl -i -H "Accept: application/xml" http://localhost:4567/
 
echo "---"
 
echo "FAIL:"
 
curl -i -H "Accept: test/html" http://localhost:4567/