File: basic.rb

package info (click to toggle)
ruby-excon 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,240 kB
  • sloc: ruby: 7,970; makefile: 5
file content (55 lines) | stat: -rw-r--r-- 756 bytes parent folder | download | duplicates (2)
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
# frozen_string_literal: true

require 'sinatra'
require 'json'

# Basic server defines requests/responses for testing
class Basic < Sinatra::Base
  set :environment, :production
  enable :dump_errors

  get('/') do
    'GET /'
  end

  get('/content-length/:value') do |value|
    headers('Custom' => 'Foo: bar')
    'x' * value.to_i
  end

  get('/headers') do
    content_type :json
    request.env.select { |key, _| key.start_with? 'HTTP_' }.to_json
  end

  post('/body-sink') do
    request.body.read.size.to_s
  end

  post('/echo') do
    echo
  end

  put('/echo') do
    echo
  end

  get('/echo dirty') do
    echo
  end

  get('/foo') do
    'foo'
  end

  get('/bar') do
    'bar'
  end

  private

  def echo
    request.body.read
  end

end