Skip to content

Commit

Permalink
net.http: copy IANA's list of methods to the http.Method enum (#18508)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoop committed Jun 22, 2023
1 parent 76ae9db commit 8b25c4c
Showing 1 changed file with 105 additions and 16 deletions.
121 changes: 105 additions & 16 deletions vlib/net/http/method.v
Expand Up @@ -3,33 +3,92 @@
// that can be found in the LICENSE file.
module http

// The methods listed here are some of the most used ones, ordered by
// commonality. A comprehensive list is available at:
// The methods listed here are all of those on the list available at:
// https://www.iana.org/assignments/http-methods/http-methods.xhtml
pub enum Method {
pub enum Method { // as of 2023-06-20
acl
baseline_control
bind
checkin
checkout
connect
copy
delete
get
post
put
head
delete
label
link
@lock
merge
mkactivity
mkcalendar
mkcol
mkredirectref
mkworkspace
move
options
trace
connect
orderpatch
patch
post
pri
propfind
proppatch
put
rebind
report
search
trace
unbind
uncheckout
unlink
unlock
update
updateredirectref
version_control
}

// str returns the string representation of the HTTP Method `m`.
pub fn (m Method) str() string {
return match m {
.get { 'GET' }
.post { 'POST' }
.put { 'PUT' }
.head { 'HEAD' }
.post { 'POST' }
.acl { 'ACL' }
.baseline_control { 'BASELINE-CONTROL' }
.bind { 'BIND' }
.checkin { 'CHECKIN' }
.checkout { 'CHECKOUT' }
.connect { 'CONNECT' }
.copy { 'COPY' }
.delete { 'DELETE' }
.label { 'LABEL' }
.link { 'LINK' }
.@lock { 'LOCK' }
.merge { 'MERGE' }
.mkactivity { 'MKACTIVITY' }
.mkcalendar { 'MKCALENDAR' }
.mkcol { 'MKCOL' }
.mkredirectref { 'MKREDIRECTREF' }
.mkworkspace { 'MKWORKSPACE' }
.move { 'MOVE' }
.options { 'OPTIONS' }
.trace { 'TRACE' }
.connect { 'CONNECT' }
.orderpatch { 'ORDERPATCH' }
.patch { 'PATCH' }
.pri { 'PRI' }
.propfind { 'PROPFIND' }
.proppatch { 'PROPPATCH' }
.put { 'PUT' }
.rebind { 'REBIND' }
.report { 'REPORT' }
.search { 'SEARCH' }
.trace { 'TRACE' }
.unbind { 'UNBIND' }
.uncheckout { 'UNCHECKOUT' }
.unlink { 'UNLINK' }
.unlock { 'UNLOCK' }
.update { 'UPDATE' }
.updateredirectref { 'UPDATEREDIRECTREF' }
.version_control { 'VERSION-CONTROL' }
}
}

Expand All @@ -40,14 +99,44 @@ pub fn (m Method) str() string {
pub fn method_from_str(m string) Method {
return match m {
'GET' { Method.get }
'POST' { Method.post }
'PUT' { Method.put }
'HEAD' { Method.head }
'POST' { Method.post }
'ACL' { Method.acl }
'BASELINE-CONTROL' { Method.baseline_control }
'BIND' { Method.bind }
'CHECKIN' { Method.checkin }
'CHECKOUT' { Method.checkout }
'CONNECT' { Method.connect }
'COPY' { Method.copy }
'DELETE' { Method.delete }
'LABEL' { Method.label }
'LINK' { Method.link }
'LOCK' { Method.@lock }
'MERGE' { Method.merge }
'MKACTIVITY' { Method.mkactivity }
'MKCALENDAR' { Method.mkcalendar }
'MKCOL' { Method.mkcol }
'MKREDIRECTREF' { Method.mkredirectref }
'MKWORKSPACE' { Method.mkworkspace }
'MOVE' { Method.move }
'OPTIONS' { Method.options }
'TRACE' { Method.trace }
'CONNECT' { Method.connect }
'ORDERPATCH' { Method.orderpatch }
'PATCH' { Method.patch }
'PRI' { Method.pri }
'PROPFIND' { Method.propfind }
'PROPPATCH' { Method.proppatch }
'PUT' { Method.put }
'REBIND' { Method.rebind }
'REPORT' { Method.report }
'SEARCH' { Method.search }
'TRACE' { Method.trace }
'UNBIND' { Method.unbind }
'UNCHECKOUT' { Method.uncheckout }
'UNLINK' { Method.unlink }
'UNLOCK' { Method.unlock }
'UPDATE' { Method.update }
'UPDATEREDIRECTREF' { Method.updateredirectref }
'VERSION-CONTROL' { Method.version_control }
else { Method.get } // should we default to GET?
}
}

0 comments on commit 8b25c4c

Please sign in to comment.