Skip to content

Commit 6c3aa83

Browse files
committed
Stdlib::Http::Method: Add new type for http methods
This PR creates new new resources: * Stdlib::Http::Method for validating http methods * Stdlib::Http::Status This is just a copy of Stdlib::Httpstatus * make Stdlib::Httpstatus and alias to Stdlib::Http::Status Ideally we would deprecate Stdlib::Httpstatus in favour of Stdlib::Http::Status
1 parent 57b339a commit 6c3aa83

File tree

5 files changed

+122
-1
lines changed

5 files changed

+122
-1
lines changed

Diff for: spec/type_aliases/http__method_spec.rb

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require 'spec_helper'
2+
3+
describe 'Stdlib::Http::Method' do
4+
describe 'valid HTTP Methods' do
5+
[
6+
'HEAD',
7+
'GET',
8+
'PUT',
9+
'DELETE',
10+
'TRACE',
11+
].each do |value|
12+
describe value.inspect do
13+
it { is_expected.to allow_value(value) }
14+
end
15+
end
16+
end
17+
18+
describe 'invalid path handling' do
19+
context 'garbage inputs' do
20+
[
21+
nil,
22+
[nil],
23+
[nil, nil],
24+
{ 'foo' => 'bar' },
25+
{},
26+
'',
27+
'https',
28+
'199',
29+
600,
30+
1_000,
31+
'Ok',
32+
'get',
33+
].each do |value|
34+
describe value.inspect do
35+
it { is_expected.not_to allow_value(value) }
36+
end
37+
end
38+
end
39+
end
40+
end

Diff for: spec/type_aliases/http__status_spec.rb

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require 'spec_helper'
2+
3+
describe 'Stdlib::Http::Status' do
4+
describe 'valid HTTP Status' do
5+
[
6+
200,
7+
302,
8+
404,
9+
418,
10+
503,
11+
].each do |value|
12+
describe value.inspect do
13+
it { is_expected.to allow_value(value) }
14+
end
15+
end
16+
end
17+
18+
describe 'invalid path handling' do
19+
context 'garbage inputs' do
20+
[
21+
nil,
22+
[nil],
23+
[nil, nil],
24+
{ 'foo' => 'bar' },
25+
{},
26+
'',
27+
'https',
28+
'199',
29+
600,
30+
1_000,
31+
].each do |value|
32+
describe value.inspect do
33+
it { is_expected.not_to allow_value(value) }
34+
end
35+
end
36+
end
37+
end
38+
end

Diff for: types/http/method.pp

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# https://www.iana.org/assignments/http-methods/http-methods.xhtml
2+
type Stdlib::Http::Method = Enum[
3+
'ACL',
4+
'BASELINE-CONTROL',
5+
'BIND',
6+
'CHECKIN',
7+
'CHECKOUT',
8+
'CONNECT',
9+
'COPY',
10+
'DELETE',
11+
'GET',
12+
'HEAD',
13+
'LABEL',
14+
'LINK',
15+
'LOCK',
16+
'MERGE',
17+
'MKACTIVITY',
18+
'MKCALENDAR',
19+
'MKCOL',
20+
'MKREDIRECTREF',
21+
'MKWORKSPACE',
22+
'MOVE',
23+
'OPTIONS',
24+
'ORDERPATCH',
25+
'PATCH',
26+
'POST',
27+
'PRI',
28+
'PROPFIND',
29+
'PROPPATCH',
30+
'PUT',
31+
'REBIND',
32+
'REPORT',
33+
'SEARCH',
34+
'TRACE',
35+
'UNBIND',
36+
'UNCHECKOUT',
37+
'UNLINK',
38+
'UNLOCK',
39+
'UPDATE',
40+
'UPDATEREDIRECTREF',
41+
'VERSION-CONTROL',
42+
]

Diff for: types/http/status.pp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type Stdlib::Http::Status = Integer[100, 599]

Diff for: types/httpstatus.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
type Stdlib::HttpStatus = Integer[100, 599]
1+
type Stdlib::HttpStatus = Stdlib::Http::Status

0 commit comments

Comments
 (0)