http.go 649 B

123456789101112131415161718192021222324252627282930
  1. package handler
  2. import (
  3. "ehang.io/nps/lib/enet"
  4. "net/http"
  5. )
  6. type HttpHandler struct {
  7. DefaultHandler
  8. }
  9. func NewHttpHandler() *HttpHandler {
  10. return &HttpHandler{}
  11. }
  12. func (h *HttpHandler) GetName() string {
  13. return "http"
  14. }
  15. func (h *HttpHandler) GetZhName() string {
  16. return "http协议"
  17. }
  18. func (h *HttpHandler) HandleConn(b []byte, c enet.Conn) (bool, error) {
  19. switch string(b[:3]) {
  20. case http.MethodGet[:3], http.MethodHead[:3], http.MethodPost[:3], http.MethodPut[:3], http.MethodPatch[:3], http.MethodDelete[:3], http.MethodConnect[:3], http.MethodOptions[:3], http.MethodTrace[:3]:
  21. return h.processConn(c)
  22. }
  23. return false, nil
  24. }