Browse Source

修复 bug

张富强 3 months ago
parent
commit
ec89e63d53
2 changed files with 18 additions and 19 deletions
  1. 6 7
      hpsocket/server_http_windows.go
  2. 12 12
      strings/to_windows.go

+ 6 - 7
hpsocket/server_http_windows.go

@@ -3,7 +3,6 @@
 package yu_hpsocket
 
 import (
-	yu_fast "gogs.qqck.cn/s/go-tools/fast"
 	yu_http "gogs.qqck.cn/s/go-tools/http"
 	yu_strings "gogs.qqck.cn/s/go-tools/strings"
 	yu_win "gogs.qqck.cn/s/go-tools/win"
@@ -106,10 +105,10 @@ func (t *HttpServer) SendResponse(ConnID uintptr, StatusCode yu_http.Status, Des
 	var j_headers_ptr unsafe.Pointer
 	if len(Headers) > 0 {
 		for j_i := 0; j_i < len(Headers); j_i++ {
-			j_headers_buf[j_i][0] = yu_fast.S2B(Headers[j_i].Name)
+			j_headers_buf[j_i][0] = yu_strings.Utf8ToGbkBytes(Headers[j_i].Name)
 			j_headers[j_i][0] = unsafe.Pointer(&j_headers_buf[j_i][0][0])
 
-			j_headers_buf[j_i][1] = yu_fast.S2B(Headers[j_i].Value)
+			j_headers_buf[j_i][1] = yu_strings.Utf8ToGbkBytes(Headers[j_i].Value)
 			j_headers[j_i][1] = unsafe.Pointer(&j_headers_buf[j_i][1][0])
 		}
 		j_headers_ptr = unsafe.Pointer(&j_headers[0])
@@ -140,10 +139,10 @@ func (t *HttpServer) SendResponseS(ConnID uintptr, StatusCode yu_http.Status, De
 	var j_headers_ptr unsafe.Pointer
 	if len(Headers) > 0 {
 		for j_i := 0; j_i < len(Headers); j_i++ {
-			j_headers_buf[j_i][0] = yu_fast.S2B(Headers[j_i].Name)
+			j_headers_buf[j_i][0] = yu_strings.Utf8ToGbkBytes(Headers[j_i].Name)
 			j_headers[j_i][0] = unsafe.Pointer(&j_headers_buf[j_i][0][0])
 
-			j_headers_buf[j_i][1] = yu_fast.S2B(Headers[j_i].Value)
+			j_headers_buf[j_i][1] = yu_strings.Utf8ToGbkBytes(Headers[j_i].Value)
 			j_headers[j_i][1] = unsafe.Pointer(&j_headers_buf[j_i][1][0])
 		}
 		j_headers_ptr = unsafe.Pointer(&j_headers[0])
@@ -200,10 +199,10 @@ func (t *HttpServer) SendLocalFile(ConnID uintptr, FileName string, StatusCode y
 	var j_headers_ptr unsafe.Pointer
 	if len(Headers) > 0 {
 		for j_i := 0; j_i < len(Headers); j_i++ {
-			j_headers_buf[j_i][0] = yu_fast.S2B(Headers[j_i].Name)
+			j_headers_buf[j_i][0] = yu_strings.Utf8ToGbkBytes(Headers[j_i].Name)
 			j_headers[j_i][0] = unsafe.Pointer(&j_headers_buf[j_i][0][0])
 
-			j_headers_buf[j_i][1] = yu_fast.S2B(Headers[j_i].Value)
+			j_headers_buf[j_i][1] = yu_strings.Utf8ToGbkBytes(Headers[j_i].Value)
 			j_headers[j_i][1] = unsafe.Pointer(&j_headers_buf[j_i][1][0])
 		}
 		j_headers_ptr = unsafe.Pointer(&j_headers[0])

+ 12 - 12
strings/to_windows.go

@@ -47,18 +47,18 @@ import (
 // 	return UnicodeToGbk(Utf8ToUnicode(utf8))
 // }
 
-// func Utf8ToGbkPointer(utf8 string) unsafe.Pointer {
-// 	j_utf8_len := uintptr(len(utf8))
-//
-// 	j_unicode_len := j_utf8_len * 2
-// 	j_unicode := make([]byte, j_unicode_len+2) // 结尾 {0,0}
-// 	yu_win.MultiByteToWideChar.Call(65001, 0, utf8, j_utf8_len, j_unicode, j_unicode_len)
-//
-// 	j_gbk := make([]byte, j_unicode_len+2) // 结尾 {0,0}
-// 	yu_win.WideCharToMultiByte.Call(936, 0, j_unicode, uint(yu_math.MaxUint), j_gbk, j_unicode_len, 0, 0)
-//
-// 	return unsafe.Pointer(&j_gbk[0])
-// }
+func Utf8ToGbkBytes(utf8 string) []byte {
+	j_utf8_len := uintptr(len(utf8))
+
+	j_unicode_len := j_utf8_len * 2
+	j_unicode := make([]byte, j_unicode_len+2) // 结尾 {0,0}
+	yu_win.MultiByteToWideChar.Call(65001, 0, utf8, j_utf8_len, j_unicode, j_unicode_len)
+
+	j_gbk := make([]byte, j_unicode_len+2) // 结尾 {0,0}
+	yu_win.WideCharToMultiByte.Call(936, 0, j_unicode, uint(yu_math.MaxUint), j_gbk, j_unicode_len, 0, 0)
+
+	return j_gbk
+}
 
 // func GbkToUtf8(utf8 string) string {
 // 	return UnicodeToUtf8(GbkToUnicode(utf8))