-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fxhttpserver): Added possibility to specify several HTTP methods…
… during handlers registration (#294)
- Loading branch information
Showing
9 changed files
with
523 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package fxhttpserver | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
const ( | ||
// MethodPropfind can be used on collection and property resources. | ||
MethodPropfind = "PROPFIND" | ||
// MethodReport Method can be used to get information about a resource, see rfc 3253 | ||
MethodReport = "REPORT" | ||
// AllMethods is a shortcut to specify all valid methods. | ||
AllMethods = "*" | ||
) | ||
|
||
var validMethods = []string{ | ||
http.MethodConnect, | ||
http.MethodDelete, | ||
http.MethodGet, | ||
http.MethodHead, | ||
http.MethodOptions, | ||
http.MethodPatch, | ||
http.MethodPost, | ||
http.MethodPut, | ||
http.MethodTrace, | ||
MethodPropfind, | ||
MethodReport, | ||
} | ||
|
||
func ExtractMethods(methods string) ([]string, error) { | ||
if methods == AllMethods { | ||
return validMethods, nil | ||
} | ||
|
||
var extractedMethods []string | ||
|
||
for _, method := range Split(methods) { | ||
method = strings.ToUpper(method) | ||
|
||
if Contains(validMethods, method) { | ||
extractedMethods = append(extractedMethods, method) | ||
} else { | ||
return nil, fmt.Errorf("invalid HTTP method %q", method) | ||
} | ||
} | ||
|
||
return extractedMethods, nil | ||
} |
Oops, something went wrong.