-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.rb
63 lines (52 loc) · 1.1 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'sinatra/base'
$stdout.sync = true
class App < Sinatra::Base
use Rack::CommonLogger
get '/get' do
'OK'
end
get '/get-header' do
test_header
'OK'
end
get '/get-headers' do
test_two_headers
'OK'
end
delete '/del' do
'OK'
end
[:put, :post, :delete].each do |method|
self.send(method, '/data') do
test_post_body
'OK'
end
self.send(method, '/data-header') do
test_post_body
test_header
'OK'
end
self.send(method, '/data-headers') do
test_post_body
test_two_headers
'OK'
end
end
private
def test_header
header = env['HTTP_X_TEST_HEADER']
puts "test_header=#{header}"
halt 420, 'FAIL' unless header == 'true'
end
def test_two_headers
header1 = env['HTTP_X_TEST_HEADER1']
header2 = env['HTTP_X_TEST_HEADER2']
puts "header1=#{header1} header2=#{header2}"
halt 420, 'FAIL' unless header1 == 'one' && header2 == 'two'
end
def test_post_body
postbody = request.body.read
puts "body=#{postbody}"
halt 420, 'FAIL' unless postbody == "POSTDATA"
end
end