Skip to content

Commit 89d78c1

Browse files
b4ldrekohl
andcommitted
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 Co-authored-by: Ewoud Kohl van Wijngaarden <[email protected]>
1 parent a54b072 commit 89d78c1

File tree

6 files changed

+151
-2
lines changed

6 files changed

+151
-2
lines changed

Diff for: REFERENCE.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ OpenSSL.
289289
* [`Stdlib::HTTPSUrl`](#Stdlib--HTTPSUrl): Validate a HTTPS URL
290290
* [`Stdlib::HTTPUrl`](#Stdlib--HTTPUrl): Validate a HTTP(S) URL
291291
* [`Stdlib::Host`](#Stdlib--Host): Validate a host (FQDN or IP address)
292+
* [`Stdlib::Http::Method`](#Stdlib--Http--Method): Valid HTTP method verbs
293+
* [`Stdlib::Http::Status`](#Stdlib--Http--Status): A valid HTTP status code per RFC9110
292294
* [`Stdlib::HttpStatus`](#Stdlib--HttpStatus): Validate a HTTP status code
293295
* [`Stdlib::IP::Address`](#Stdlib--IP--Address): Validate an IP address
294296
* [`Stdlib::IP::Address::Nosubnet`](#Stdlib--IP--Address--Nosubnet): Validate an IP address without subnet
@@ -7796,11 +7798,32 @@ Validate a host (FQDN or IP address)
77967798

77977799
Alias of `Variant[Stdlib::Fqdn, Stdlib::Compat::Ip_address]`
77987800

7801+
### <a name="Stdlib--Http--Method"></a>`Stdlib::Http::Method`
7802+
7803+
Valid HTTP method verbs
7804+
7805+
* **See also**
7806+
* https://www.iana.org/assignments/http-methods/http-methods.xhtml
7807+
7808+
Alias of `Enum['ACL', 'BASELINE-CONTROL', 'BIND', 'CHECKIN', 'CHECKOUT', 'CONNECT', 'COPY', 'DELETE', 'GET', 'HEAD', 'LABEL', 'LINK', 'LOCK', 'MERGE', 'MKACTIVITY', 'MKCALENDAR', 'MKCOL', 'MKREDIRECTREF', 'MKWORKSPACE', 'MOVE', 'OPTIONS', 'ORDERPATCH', 'PATCH', 'POST', 'PRI', 'PROPFIND', 'PROPPATCH', 'PUT', 'REBIND', 'REPORT', 'SEARCH', 'TRACE', 'UNBIND', 'UNCHECKOUT', 'UNLINK', 'UNLOCK', 'UPDATE', 'UPDATEREDIRECTREF', 'VERSION-CONTROL']`
7809+
7810+
### <a name="Stdlib--Http--Status"></a>`Stdlib::Http::Status`
7811+
7812+
A valid HTTP status code per RFC9110
7813+
7814+
* **See also**
7815+
* https://httpwg.org/specs/rfc9110.html#overview.of.status.codes
7816+
7817+
Alias of `Integer[100, 599]`
7818+
77997819
### <a name="Stdlib--HttpStatus"></a>`Stdlib::HttpStatus`
78007820

78017821
Validate a HTTP status code
78027822

7803-
Alias of `Integer[100, 599]`
7823+
* **See also**
7824+
* Stdlib::Http::Status
7825+
7826+
Alias of `Stdlib::Http::Status`
78047827

78057828
### <a name="Stdlib--IP--Address"></a>`Stdlib::IP::Address`
78067829

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

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

Diff for: types/http/status.pp

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @summary A valid HTTP status code per RFC9110
2+
# @see https://httpwg.org/specs/rfc9110.html#overview.of.status.codes
3+
type Stdlib::Http::Status = Integer[100, 599]

Diff for: types/httpstatus.pp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# @summary Validate a HTTP status code
2-
type Stdlib::HttpStatus = Integer[100, 599]
2+
# @deprecated Use Stdlib::Http::Status
3+
# @see Stdlib::Http::Status
4+
type Stdlib::HttpStatus = Stdlib::Http::Status

0 commit comments

Comments
 (0)