filter.go 804 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package main
  2. import (
  3. "log"
  4. "strings"
  5. )
  6. var methodList = []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"}
  7. func filter(args []string) []string {
  8. var i int
  9. if inSlice(strings.ToUpper(args[i]), methodList) {
  10. *method = strings.ToUpper(args[i])
  11. i++
  12. } else if len(args) > 0 && *method == "GET" {
  13. for _, v := range args[1:] {
  14. // defaults to either GET (with no request data) or POST (with request data).
  15. // Params
  16. strs := strings.Split(v, "=")
  17. if len(strs) == 2 {
  18. *method = "POST"
  19. break
  20. }
  21. // files
  22. strs = strings.Split(v, "@")
  23. if len(strs) == 2 {
  24. *method = "POST"
  25. break
  26. }
  27. }
  28. } else if *method == "GET" && body != "" {
  29. *method = "POST"
  30. }
  31. if len(args) <= i {
  32. log.Fatal("Miss the URL")
  33. }
  34. *URL = args[i]
  35. i++
  36. return args[i:]
  37. }