111
All checks were successful
Build Multi-Platform Binaries / build-frontend (push) Successful in 32s
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Successful in 1m52s
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Successful in 1m54s
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Successful in 1m18s
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Successful in 1m45s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, client, true) (push) Successful in 1m3s
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Successful in 1m28s
Build Multi-Platform Binaries / build-binaries (arm64, darwin, server, false) (push) Successful in 1m41s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, server, true) (push) Successful in 1m51s
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Successful in 1m11s
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Successful in 1m40s
Build Multi-Platform Binaries / build-binaries (arm64, windows, server, false) (push) Successful in 1m9s
All checks were successful
Build Multi-Platform Binaries / build-frontend (push) Successful in 32s
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Successful in 1m52s
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Successful in 1m54s
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Successful in 1m18s
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Successful in 1m45s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, client, true) (push) Successful in 1m3s
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Successful in 1m28s
Build Multi-Platform Binaries / build-binaries (arm64, darwin, server, false) (push) Successful in 1m41s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, server, true) (push) Successful in 1m51s
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Successful in 1m11s
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Successful in 1m40s
Build Multi-Platform Binaries / build-binaries (arm64, windows, server, false) (push) Successful in 1m9s
This commit is contained in:
@@ -401,83 +401,91 @@ func (p *JSPlugin) httpServe(conn net.Conn, handler goja.Callable) {
|
|||||||
// Use bufio to read the request properly
|
// Use bufio to read the request properly
|
||||||
reader := bufio.NewReader(conn)
|
reader := bufio.NewReader(conn)
|
||||||
|
|
||||||
// 1. Read Request Line
|
|
||||||
line, err := reader.ReadString('\n')
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("[JS:%s] httpServe read error: %v\n", p.name, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
line = strings.TrimSpace(line)
|
|
||||||
parts := strings.Split(line, " ")
|
|
||||||
if len(parts) < 2 {
|
|
||||||
fmt.Printf("[JS:%s] Invalid request line: %s\n", p.name, line)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
method := parts[0]
|
|
||||||
path := parts[1]
|
|
||||||
|
|
||||||
fmt.Printf("[JS:%s] Request: %s %s\n", p.name, method, path)
|
|
||||||
|
|
||||||
// 2. Read Headers
|
|
||||||
headers := make(map[string]string)
|
|
||||||
contentLength := 0
|
|
||||||
for {
|
for {
|
||||||
hLine, err := reader.ReadString('\n')
|
// 1. Read Request Line
|
||||||
|
line, err := reader.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
if err != io.EOF {
|
||||||
|
fmt.Printf("[JS:%s] httpServe read error: %v\n", p.name, err)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
hLine = strings.TrimSpace(hLine)
|
line = strings.TrimSpace(line)
|
||||||
if hLine == "" {
|
if line == "" {
|
||||||
break
|
continue
|
||||||
}
|
}
|
||||||
if idx := strings.Index(hLine, ":"); idx > 0 {
|
|
||||||
key := strings.TrimSpace(hLine[:idx])
|
parts := strings.Split(line, " ")
|
||||||
val := strings.TrimSpace(hLine[idx+1:])
|
if len(parts) < 2 {
|
||||||
headers[strings.ToLower(key)] = val
|
fmt.Printf("[JS:%s] Invalid request line: %s\n", p.name, line)
|
||||||
if strings.ToLower(key) == "content-length" {
|
return
|
||||||
contentLength, _ = strconv.Atoi(val)
|
}
|
||||||
|
method := parts[0]
|
||||||
|
path := parts[1]
|
||||||
|
|
||||||
|
fmt.Printf("[JS:%s] Request: %s %s\n", p.name, method, path)
|
||||||
|
|
||||||
|
// 2. Read Headers
|
||||||
|
headers := make(map[string]string)
|
||||||
|
contentLength := 0
|
||||||
|
for {
|
||||||
|
hLine, err := reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
hLine = strings.TrimSpace(hLine)
|
||||||
|
if hLine == "" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if idx := strings.Index(hLine, ":"); idx > 0 {
|
||||||
|
key := strings.TrimSpace(hLine[:idx])
|
||||||
|
val := strings.TrimSpace(hLine[idx+1:])
|
||||||
|
headers[strings.ToLower(key)] = val
|
||||||
|
if strings.ToLower(key) == "content-length" {
|
||||||
|
contentLength, _ = strconv.Atoi(val)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Read Body
|
// 3. Read Body
|
||||||
body := ""
|
body := ""
|
||||||
if contentLength > 0 {
|
if contentLength > 0 {
|
||||||
bodyBuf := make([]byte, contentLength)
|
bodyBuf := make([]byte, contentLength)
|
||||||
if _, err := io.ReadFull(reader, bodyBuf); err == nil {
|
if _, err := io.ReadFull(reader, bodyBuf); err == nil {
|
||||||
body = string(bodyBuf)
|
body = string(bodyBuf)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
req := map[string]interface{}{
|
req := map[string]interface{}{
|
||||||
"method": method,
|
"method": method,
|
||||||
"path": path,
|
"path": path,
|
||||||
"headers": headers,
|
"headers": headers,
|
||||||
"body": body,
|
"body": body,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用 JS handler 函数
|
// 调用 JS handler 函数
|
||||||
result, err := handler(goja.Undefined(), p.vm.ToValue(req))
|
result, err := handler(goja.Undefined(), p.vm.ToValue(req))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("[JS:%s] HTTP handler error: %v\n", p.name, err)
|
fmt.Printf("[JS:%s] HTTP handler error: %v\n", p.name, err)
|
||||||
conn.Write([]byte("HTTP/1.1 500 Internal Server Error\r\n\r\n"))
|
conn.Write([]byte("HTTP/1.1 500 Internal Server Error\r\nConnection: close\r\n\r\n"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将结果转换为 map
|
// 将结果转换为 map
|
||||||
if result == nil || goja.IsUndefined(result) || goja.IsNull(result) {
|
if result == nil || goja.IsUndefined(result) || goja.IsNull(result) {
|
||||||
conn.Write([]byte("HTTP/1.1 200 OK\r\n\r\n"))
|
conn.Write([]byte("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"))
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := make(map[string]interface{})
|
resp := make(map[string]interface{})
|
||||||
respObj := result.ToObject(p.vm)
|
respObj := result.ToObject(p.vm)
|
||||||
for _, key := range respObj.Keys() {
|
for _, key := range respObj.Keys() {
|
||||||
val := respObj.Get(key)
|
val := respObj.Get(key)
|
||||||
resp[key] = val.Export()
|
resp[key] = val.Export()
|
||||||
}
|
}
|
||||||
|
|
||||||
writeHTTPResponse(conn, resp)
|
writeHTTPResponse(conn, resp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *JSPlugin) httpJSON(data interface{}) string {
|
func (p *JSPlugin) httpJSON(data interface{}) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user