File tree Expand file tree Collapse file tree 1 file changed +29
-11
lines changed Expand file tree Collapse file tree 1 file changed +29
-11
lines changed Original file line number Diff line number Diff line change 2
2
$stdout. sync = true
3
3
4
4
class App < Sinatra ::Base
5
+ use Rack ::CommonLogger
6
+
5
7
get '/get' do
6
- puts "/get"
7
8
'OK'
8
9
end
9
10
10
11
get '/get-header' do
11
- puts "/get-header"
12
12
test_header
13
13
'OK'
14
14
end
15
15
16
- post '/post' do
17
- puts "/post"
18
- test_post_body
16
+ get '/get-headers' do
17
+ test_two_headers
19
18
'OK'
20
19
end
21
20
22
- post '/post-headers' do
23
- puts '/post-headers'
24
- test_post_body
25
- test_header
26
- 'OK'
21
+ [ :put , :post , :delete ] . each do |method |
22
+ self . send ( method , '/data' ) do
23
+ test_post_body
24
+ 'OK'
25
+ end
26
+
27
+ self . send ( method , '/data-header' ) do
28
+ test_post_body
29
+ test_header
30
+ 'OK'
31
+ end
32
+
33
+ self . send ( method , '/data-headers' ) do
34
+ test_post_body
35
+ test_two_headers
36
+ 'OK'
37
+ end
27
38
end
28
39
29
40
private
@@ -33,8 +44,15 @@ def test_header
33
44
halt 420 , 'FAIL' unless header == 'true'
34
45
end
35
46
47
+ def test_two_headers
48
+ header1 = env [ 'HTTP_X_TEST_HEADER1' ]
49
+ header2 = env [ 'HTTP_X_TEST_HEADER2' ]
50
+ puts "header1=#{ header1 } header2=#{ header2 } "
51
+ halt 420 , 'FAIL' unless header1 == 'one' && header2 == 'two'
52
+ end
53
+
36
54
def test_post_body
37
- postbody = request . body . string
55
+ postbody = request . body . read
38
56
puts "body=#{ postbody } "
39
57
halt 420 , 'FAIL' unless postbody == "POSTDATA"
40
58
end
You can’t perform that action at this time.
0 commit comments