-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.rb
67 lines (54 loc) · 2.11 KB
/
serve.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
64
65
66
67
require 'sinatra'
require 'securerandom'
$pwd = Dir.pwd
def serve_xml(file)
content_type 'application/xml'
headers \
"last-modified" => "Tue, 16 Aug 2022 20:58:48 GMT",
"for_testing" => SecureRandom.uuid
send_file($pwd + file)
end
def serve_gzipped_xml(file)
content_type 'application/xml'
headers \
"last-modified" => "Tue, 16 Aug 2022 20:58:48 GMT",
"for_testing" => SecureRandom.uuid ,
'Content-Encoding' => 'gzip'
gz = Zlib::GzipWriter.new(StringIO.new)
gz.write(File.read($pwd + file))
gz.close.string
end
get '/climateweb/rest/v1/country/annualavg/pr/1980/1999/fra.xml' do
serve_gzipped_xml("/climateweb/rest/v1/country/annualavg/pr/1980/1999/fra.xml")
end
get '/climateweb/rest/v1/country/annualavg/pr/1980/1999/gbr.xml' do
serve_gzipped_xml("/climateweb/rest/v1/country/annualavg/pr/1980/1999/gbr.xml")
end
get '/climateweb/rest/v1/country/annualavg/pr/1985/1995/gbr.xml' do
serve_gzipped_xml("/climateweb/rest/v1/country/annualavg/pr/1985/1995/gbr.xml")
end
get '/no-gzip/climateweb/rest/v1/country/annualavg/pr/1980/1999/egy.xml' do
serve_xml("/climateweb/rest/v1/country/annualavg/pr/1980/1999/egy.xml")
end
get '/no-gzip/climateweb/rest/v1/country/annualavg/pr/1980/1999/mde.xml' do
serve_xml("/climateweb/rest/v1/country/annualavg/pr/1980/1999/mde.xml")
end
get '/no-gzip/climateweb/rest/v1/country/annualavg/pr/1980/1999/fra.xml' do
serve_xml("/climateweb/rest/v1/country/annualavg/pr/1980/1999/fra.xml")
end
get '/no-gzip/climateweb/rest/v1/country/annualavg/pr/1980/1999/gbr.xml' do
serve_xml("/climateweb/rest/v1/country/annualavg/pr/1980/1999/gbr.xml")
end
get '/no-gzip/climateweb/rest/v1/country/annualavg/pr/1985/1995/gbr.xml' do
serve_xml("/climateweb/rest/v1/country/annualavg/pr/1985/1995/gbr.xml")
end
get '/no-gzip/climateweb/rest/v1/country/annualavg/pr/1980/1999/egy.xml' do
serve_xml("/climateweb/rest/v1/country/annualavg/pr/1980/1999/egy.xml")
end
get '/no-gzip/climateweb/rest/v1/country/annualavg/pr/1980/1999/mde.xml' do
serve_gzipped_xml("/climateweb/rest/v1/country/annualavg/pr/1980/1999/mde.xml")
end
not_found do
status_code 404
"not found"
end