server_http_windows_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //go:build windows
  2. package yu_hpsocket
  3. import (
  4. "fmt"
  5. yu_http "gogs.qqck.cn/s/tools/http"
  6. "testing"
  7. "time"
  8. )
  9. func TestHPsocketHttpServer(t *testing.T) {
  10. j_server := NewHttpServer()
  11. fmt.Println(j_server.Create(false))
  12. j_server.OnMessageBegin(func(t *HttpServer, Sender, ConnID uintptr) HPR {
  13. fmt.Println("HttpServer.OnMessageBegin", Sender, ConnID)
  14. return HPR_OK
  15. })
  16. j_server.OnRequestLine(func(t *HttpServer, Sender, ConnID uintptr, Method, Url string) HPR {
  17. fmt.Println("HttpServer.OnRequestLine", Sender, ConnID, Method, Url)
  18. return HPR_OK
  19. })
  20. j_server.OnHeadersComplete(func(t *HttpServer, Sender, ConnID uintptr) HPR {
  21. fmt.Println("HttpServer.OnHeadersComplete", Sender, ConnID)
  22. // testHPsocketHttpServerCall(t, ConnID)
  23. return HPR_OK
  24. })
  25. j_server.OnBody(func(t *HttpServer, Sender, ConnID, Data uintptr, Length uintptr) HPR {
  26. fmt.Println("HttpServer.OnBody", Sender, ConnID, Data, Length)
  27. return HPR_OK
  28. })
  29. j_server.OnChunkHeader(func(t *HttpServer, Sender, ConnID uintptr, Length uintptr) HPR {
  30. fmt.Println("HttpServer.OnChunkHeader", Sender, ConnID, Length)
  31. return HPR_OK
  32. })
  33. j_server.OnChunkComplete(func(t *HttpServer, Sender, ConnID uintptr) HPR {
  34. fmt.Println("HttpServer.OnChunkComplete", Sender, ConnID)
  35. return HPR_OK
  36. })
  37. j_server.OnMessageComplete(func(t *HttpServer, Sender, ConnID uintptr) HPR {
  38. fmt.Println("HttpServer.OnMessageComplete", Sender, ConnID)
  39. fmt.Println("HttpServer.GetAllHeaders", t.GetAllHeaders(ConnID))
  40. t.SendResponseS(ConnID, yu_http.StatusOK, "OK", []TNVPair{
  41. {"qwewqewqe", "Upgrade;aasdasd;wwqeqwe;"},
  42. {"Accept", "text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8"},
  43. {"Accept", "text/ht"},
  44. }, "nilnilnilnilnilnilnilnilnilnilnil")
  45. return HPR_OK
  46. })
  47. j_server.OnUpgrade(func(t *HttpServer, Sender, ConnID uintptr, UpgradeType HUT) HPR {
  48. fmt.Println("HttpServer.OnUpgrade", Sender, ConnID, UpgradeType)
  49. switch UpgradeType {
  50. case HUT_WEB_SOCKET:
  51. t.SendResponse(ConnID, yu_http.StatusSwitchingProtocols, "", []TNVPair{
  52. {"Connection", "Upgrade"},
  53. {"Upgrade", "WebSocket"},
  54. }, nil)
  55. }
  56. return HPR_OK
  57. })
  58. j_server.OnParseError(func(t *HttpServer, Sender, ConnID uintptr, ErrorCode int, ErrorDesc string) HPR {
  59. fmt.Println("HttpServer.OnParseError", Sender, ConnID, ErrorCode, ErrorDesc)
  60. return HPR_OK
  61. })
  62. j_server.OnWSMessageHeader(func(t *HttpServer, Sender, ConnID uintptr, Final bool, Reserved, OperationCode byte, Mask []byte, BodyLen int64) HR {
  63. fmt.Println("HttpServer.OnWSMessageHeader", Sender, ConnID, Final, Reserved, OperationCode, Mask, BodyLen)
  64. return HR_OK
  65. })
  66. j_server.OnWSMessageBody(func(t *HttpServer, Sender, ConnID, Data uintptr, Length uintptr) HR {
  67. fmt.Println("HttpServer.OnWSMessageBody", Sender, ConnID, Data, Length)
  68. return HR_OK
  69. })
  70. j_server.OnWSMessageComplete(func(t *HttpServer, Sender, ConnID uintptr) HR {
  71. fmt.Println("HttpServer.OnWSMessageComplete", Sender, ConnID)
  72. return HR_OK
  73. })
  74. j_server.OnPrepareListen(func(t *HttpServer, Sender, Listen uintptr) HR {
  75. fmt.Println("HttpServer.OnPrepareListen", Sender, Listen)
  76. return HR_OK
  77. })
  78. j_server.OnAccept(func(t *HttpServer, Sender, ConnID, Client uintptr) HR {
  79. fmt.Println("HttpServer.OnAccept", ConnID, Client)
  80. return HR_OK
  81. })
  82. j_server.OnHandShake(func(t *HttpServer, Sender, ConnID uintptr) HR {
  83. fmt.Println("HttpServer.OnHandShake", Sender, ConnID)
  84. return HR_OK
  85. })
  86. j_server.OnSend(func(t *HttpServer, Sender, ConnID, Data uintptr, Length uintptr) HR {
  87. fmt.Println("HttpServer.OnSend", Sender, ConnID, Data, Length)
  88. return HR_OK
  89. })
  90. j_server.OnReceive(func(t *HttpServer, Sender, ConnID, Data uintptr, Length uintptr) HR {
  91. fmt.Println("HttpServer.OnReceive", Sender, ConnID, Data, Length)
  92. return HR_OK
  93. })
  94. j_server.OnClose(func(t *HttpServer, Sender, ConnID uintptr, Operation SO, ErrorCode int) HR {
  95. fmt.Println("HttpServer.OnClose", Sender, ConnID, Operation, ErrorCode)
  96. return HR_OK
  97. })
  98. j_server.OnShutdown(func(t *HttpServer, Sender uintptr) HR {
  99. fmt.Println("HttpServer.OnShutdown", Sender)
  100. return HR_OK
  101. })
  102. fmt.Println(j_server.Start("0.0.0.0", 8001))
  103. fmt.Println(j_server.GetLastError(), j_server.GetLastErrorDesc())
  104. time.Sleep(time.Second * 100000)
  105. }