2023-03-28 23:55:57 +03:00
|
|
|
// Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved.
|
2020-07-28 10:39:10 +03:00
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
module http
|
|
|
|
|
2023-06-22 09:31:34 +03:00
|
|
|
// The methods listed here are all of those on the list available at:
|
2020-07-28 10:39:10 +03:00
|
|
|
// https://www.iana.org/assignments/http-methods/http-methods.xhtml
|
2023-06-22 09:31:34 +03:00
|
|
|
pub enum Method { // as of 2023-06-20
|
|
|
|
acl
|
|
|
|
baseline_control
|
|
|
|
bind
|
|
|
|
checkin
|
|
|
|
checkout
|
|
|
|
connect
|
|
|
|
copy
|
|
|
|
delete
|
2020-07-28 10:39:10 +03:00
|
|
|
get
|
|
|
|
head
|
2023-06-22 09:31:34 +03:00
|
|
|
label
|
|
|
|
link
|
|
|
|
@lock
|
|
|
|
merge
|
|
|
|
mkactivity
|
|
|
|
mkcalendar
|
|
|
|
mkcol
|
|
|
|
mkredirectref
|
|
|
|
mkworkspace
|
|
|
|
move
|
2020-07-28 10:39:10 +03:00
|
|
|
options
|
2023-06-22 09:31:34 +03:00
|
|
|
orderpatch
|
2020-07-28 10:39:10 +03:00
|
|
|
patch
|
2023-06-22 09:31:34 +03:00
|
|
|
post
|
|
|
|
pri
|
|
|
|
propfind
|
|
|
|
proppatch
|
|
|
|
put
|
|
|
|
rebind
|
|
|
|
report
|
|
|
|
search
|
|
|
|
trace
|
|
|
|
unbind
|
|
|
|
uncheckout
|
|
|
|
unlink
|
|
|
|
unlock
|
|
|
|
update
|
|
|
|
updateredirectref
|
|
|
|
version_control
|
2020-07-28 10:39:10 +03:00
|
|
|
}
|
|
|
|
|
2023-01-27 14:58:55 +03:00
|
|
|
// str returns the string representation of the HTTP Method `m`.
|
2020-07-28 12:34:08 +03:00
|
|
|
pub fn (m Method) str() string {
|
2020-07-28 10:39:10 +03:00
|
|
|
return match m {
|
|
|
|
.get { 'GET' }
|
|
|
|
.head { 'HEAD' }
|
2023-06-22 09:31:34 +03:00
|
|
|
.post { 'POST' }
|
|
|
|
.acl { 'ACL' }
|
|
|
|
.baseline_control { 'BASELINE-CONTROL' }
|
|
|
|
.bind { 'BIND' }
|
|
|
|
.checkin { 'CHECKIN' }
|
|
|
|
.checkout { 'CHECKOUT' }
|
|
|
|
.connect { 'CONNECT' }
|
|
|
|
.copy { 'COPY' }
|
2020-07-28 10:39:10 +03:00
|
|
|
.delete { 'DELETE' }
|
2023-06-22 09:31:34 +03:00
|
|
|
.label { 'LABEL' }
|
|
|
|
.link { 'LINK' }
|
|
|
|
.@lock { 'LOCK' }
|
|
|
|
.merge { 'MERGE' }
|
|
|
|
.mkactivity { 'MKACTIVITY' }
|
|
|
|
.mkcalendar { 'MKCALENDAR' }
|
|
|
|
.mkcol { 'MKCOL' }
|
|
|
|
.mkredirectref { 'MKREDIRECTREF' }
|
|
|
|
.mkworkspace { 'MKWORKSPACE' }
|
|
|
|
.move { 'MOVE' }
|
2020-07-28 10:39:10 +03:00
|
|
|
.options { 'OPTIONS' }
|
2023-06-22 09:31:34 +03:00
|
|
|
.orderpatch { 'ORDERPATCH' }
|
2020-07-28 10:39:10 +03:00
|
|
|
.patch { 'PATCH' }
|
2023-06-22 09:31:34 +03:00
|
|
|
.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' }
|
2020-07-28 10:39:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-27 14:58:55 +03:00
|
|
|
// method_from_str returns the corresponding Method enum field
|
|
|
|
// given a string `m`, e.g. `'GET'` would return Method.get.
|
|
|
|
//
|
|
|
|
// Currently, the default value is Method.get for unsupported string value.
|
2020-07-28 10:39:10 +03:00
|
|
|
pub fn method_from_str(m string) Method {
|
|
|
|
return match m {
|
|
|
|
'GET' { Method.get }
|
|
|
|
'HEAD' { Method.head }
|
2023-06-22 09:31:34 +03:00
|
|
|
'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 }
|
2020-07-28 10:39:10 +03:00
|
|
|
'DELETE' { Method.delete }
|
2023-06-22 09:31:34 +03:00
|
|
|
'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 }
|
2020-07-28 10:39:10 +03:00
|
|
|
'OPTIONS' { Method.options }
|
2023-06-22 09:31:34 +03:00
|
|
|
'ORDERPATCH' { Method.orderpatch }
|
2020-07-28 10:39:10 +03:00
|
|
|
'PATCH' { Method.patch }
|
2023-06-22 09:31:34 +03:00
|
|
|
'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 }
|
2020-07-28 10:39:10 +03:00
|
|
|
else { Method.get } // should we default to GET?
|
|
|
|
}
|
|
|
|
}
|