http_server.go 782 B

1234567891011121314151617181920212223242526272829303132
  1. package tests
  2. import (
  3. "fmt"
  4. "net/http"
  5. "strings"
  6. )
  7. func StartHttpServer() {
  8. http.HandleFunc("/", request)
  9. http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", TEST_HTTP_PORT), nil)
  10. }
  11. func request(w http.ResponseWriter, r *http.Request) {
  12. if strings.Contains(r.Host, "127.0.0.1") || strings.Contains(r.Host, "test2.frp.com") ||
  13. strings.Contains(r.Host, "test5.frp.com") {
  14. w.WriteHeader(200)
  15. w.Write([]byte(TEST_HTTP_NORMAL_STR))
  16. } else if strings.Contains(r.Host, "test3.frp.com") {
  17. w.WriteHeader(200)
  18. if strings.Contains(r.URL.Path, "foo") {
  19. w.Write([]byte(TEST_HTTP_FOO_STR))
  20. } else if strings.Contains(r.URL.Path, "bar") {
  21. w.Write([]byte(TEST_HTTP_BAR_STR))
  22. } else {
  23. w.Write([]byte(TEST_HTTP_NORMAL_STR))
  24. }
  25. } else {
  26. w.WriteHeader(404)
  27. }
  28. return
  29. }