Skip to content

Stdlib::Http::Method: Add new type for http methods #1299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ OpenSSL.
* [`Stdlib::HTTPSUrl`](#Stdlib--HTTPSUrl): Validate a HTTPS URL
* [`Stdlib::HTTPUrl`](#Stdlib--HTTPUrl): Validate a HTTP(S) URL
* [`Stdlib::Host`](#Stdlib--Host): Validate a host (FQDN or IP address)
* [`Stdlib::Http::Method`](#Stdlib--Http--Method): Valid HTTP method verbs
* [`Stdlib::Http::Status`](#Stdlib--Http--Status): A valid HTTP status code per RFC9110
* [`Stdlib::HttpStatus`](#Stdlib--HttpStatus): Validate a HTTP status code
* [`Stdlib::IP::Address`](#Stdlib--IP--Address): Validate an IP address
* [`Stdlib::IP::Address::Nosubnet`](#Stdlib--IP--Address--Nosubnet): Validate an IP address without subnet
Expand Down Expand Up @@ -7796,11 +7798,32 @@ Validate a host (FQDN or IP address)

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

### <a name="Stdlib--Http--Method"></a>`Stdlib::Http::Method`

Valid HTTP method verbs

* **See also**
* https://www.iana.org/assignments/http-methods/http-methods.xhtml

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']`

### <a name="Stdlib--Http--Status"></a>`Stdlib::Http::Status`

A valid HTTP status code per RFC9110

* **See also**
* https://httpwg.org/specs/rfc9110.html#overview.of.status.codes

Alias of `Integer[100, 599]`

### <a name="Stdlib--HttpStatus"></a>`Stdlib::HttpStatus`

Validate a HTTP status code

Alias of `Integer[100, 599]`
* **See also**
* Stdlib::Http::Status

Alias of `Stdlib::Http::Status`

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

Expand Down
40 changes: 40 additions & 0 deletions spec/type_aliases/http__method_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'spec_helper'

describe 'Stdlib::Http::Method' do
describe 'valid HTTP Methods' do
[
'HEAD',
'GET',
'PUT',
'DELETE',
'TRACE',
].each do |value|
describe value.inspect do
it { is_expected.to allow_value(value) }
end
end
end

describe 'invalid path handling' do
context 'garbage inputs' do
[
nil,
[nil],
[nil, nil],
{ 'foo' => 'bar' },
{},
'',
'https',
'199',
600,
1_000,
'Ok',
'get',
].each do |value|
describe value.inspect do
it { is_expected.not_to allow_value(value) }
end
end
end
end
end
38 changes: 38 additions & 0 deletions spec/type_aliases/http__status_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'spec_helper'

describe 'Stdlib::Http::Status' do
describe 'valid HTTP Status' do
[
200,
302,
404,
418,
503,
].each do |value|
describe value.inspect do
it { is_expected.to allow_value(value) }
end
end
end

describe 'invalid path handling' do
context 'garbage inputs' do
[
nil,
[nil],
[nil, nil],
{ 'foo' => 'bar' },
{},
'',
'https',
'199',
600,
1_000,
].each do |value|
describe value.inspect do
it { is_expected.not_to allow_value(value) }
end
end
end
end
end
43 changes: 43 additions & 0 deletions types/http/method.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# @summary Valid HTTP method verbs
# @see https://www.iana.org/assignments/http-methods/http-methods.xhtml
type Stdlib::Http::Method = 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',
]
3 changes: 3 additions & 0 deletions types/http/status.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @summary A valid HTTP status code per RFC9110
# @see https://httpwg.org/specs/rfc9110.html#overview.of.status.codes
type Stdlib::Http::Status = Integer[100, 599]
4 changes: 3 additions & 1 deletion types/httpstatus.pp
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# @summary Validate a HTTP status code
type Stdlib::HttpStatus = Integer[100, 599]
# @deprecated Use Stdlib::Http::Status
# @see Stdlib::Http::Status
type Stdlib::HttpStatus = Stdlib::Http::Status
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after this is merged, can you raise a new PR that removes this old type? Then we can keep it open until the next major release and won't forget it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure will do, ill leave this open for now so i dont forget