Skip to content

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

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
Jul 12, 2021
Merged
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
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
42 changes: 42 additions & 0 deletions types/http/method.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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',
]
1 change: 1 addition & 0 deletions types/http/status.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Stdlib::Http::Status = Integer[100, 599]
2 changes: 1 addition & 1 deletion types/httpstatus.pp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
type Stdlib::HttpStatus = Integer[100, 599]
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.

I wonder if this type can be deprecated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i would also like to deprecate this in favour of Stdlib::Http::Status but not sure of the process for that. i regret not namespacing this when i first introduced 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.

can always do this bit in a separate pr if that makes things easier?