Skip to content

Commit 8adefb4

Browse files
committed
Bump version to 1.9 and adjust HTTP worker count
- Updated server version from 1.8 to 1.9. - Reduced default HTTP worker count from 64 to 32. - Added new HTTP status code 502 (Bad Gateway) to state codes. - Introduced a status code map for cleaner response handling. - Consolidated error response handling into a new function `send_error_response`. - Implemented checks for too many 1xx interim responses in the HTTP client. - Simplified response status handling in the HTTP server.
1 parent e62c9bd commit 8adefb4

6 files changed

Lines changed: 117 additions & 147 deletions

File tree

NETUTILS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CovScript NetUtils 协议文档
22

3-
版本:1.8
3+
版本:1.9
44

55
作者:Covariant Script OSC
66

@@ -27,7 +27,7 @@
2727
## 2. 基本常量与工具函数
2828

2929
* `server_name = "CovScript-NetUtils"`
30-
* `server_version = "1.8"`
30+
* `server_version = "1.9"`
3131

3232
与协议/实现相关的重要工具函数:
3333

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A high-performance network extension for the [Covariant Script](http://covscript
99
| Package | Type | Version | Description |
1010
|---|---|---|---|
1111
| `network` | C++ Extension | `1.38.0_v6.4` | TCP/UDP sockets, TLS/SSL, async I/O, event loop |
12-
| `netutils` | CovScript | `1.8` | HTTP server/client framework with single-process, distributed master/slave, and OpenAI API modes |
12+
| `netutils` | CovScript | `1.9` | HTTP server/client framework with single-process, distributed master/slave, and OpenAI API modes |
1313
| `argparse` | CovScript | `1.1` | Lightweight command-line argument parser |
1414

1515
> **Note:** `netutils` and `argparse` are provided as both source (`.ecs`), compiled package (`.csp`), and bytecode module (`.csym`) — place them in your project's `imports/` directory.

csbuild/netutils.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"Name": "netutils",
44
"Info": "Network Utilities",
55
"Author": "CovScript Organization",
6-
"Version": "1.8",
6+
"Version": "1.9",
77
"Source": "netutils.ecs",
88
"Target": "netutils.csp",
99
"Dependencies": [

netutils.csp

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Generated by Extended CovScript Compiler
22
# DO NOT MODIFY
3-
# Date: Tue Jul 14 21:24:55 2026
3+
# Date: Wed Jul 15 10:47:49 2026
44
@charset: utf8
55
import ecs as netutils_ecs
66
struct __netutils_ecs_lambda_impl_1__
@@ -79,38 +79,11 @@ struct __netutils_ecs_lambda_impl_3__
7979
if resp["headers"].exist("content-type")
8080
content_type = resp["headers"]["content-type"]
8181
end
82-
var status = "200 OK"
83-
if resp["status_code"] != 200
84-
var code_str = to_string(resp["status_code"])
85-
switch resp["status_code"]
86-
case 400
87-
status = code_str + " Bad Request"
88-
end
89-
case 403
90-
status = code_str + " Forbidden"
91-
end
92-
case 404
93-
status = code_str + " Not Found"
94-
end
95-
case 408
96-
status = code_str + " Request Timeout"
97-
end
98-
case 431
99-
status = code_str + " Request Header Fields Too Large"
100-
end
101-
case 500
102-
status = code_str + " Internal Server Error"
103-
end
104-
case 502
105-
status = code_str + " Bad Gateway"
106-
end
107-
case 503
108-
status = code_str + " Service Unavailable"
109-
end
110-
default
111-
status = code_str + " Unknown"
112-
end
113-
end
82+
var status = resp["status_code"]
83+
if status_code_map.exist(status)
84+
status = status_code_map[status]
85+
else
86+
status = to_string(status) + " Unknown"
11487
end
11588
session.send_response(status, resp["body"], content_type)
11689
end
@@ -122,7 +95,7 @@ import network; using network
12295
import regex
12396
import codec.json as json
12497
constant server_name = "CovScript-NetUtils"
125-
constant server_version = "1.8"
98+
constant server_version = "1.9"
12699
constant http_client_read_chunk = 8192
127100
constant http_max_header_line_size = 8192
128101
constant http_max_header_size = 65536
@@ -131,20 +104,22 @@ constant framing_hex_size = 16
131104
constant default_http_port = 80
132105
constant default_https_port = 443
133106
constant default_http_thread_count = 4
134-
constant default_http_worker_count = 64
107+
constant default_http_worker_count = 32
135108
var request_line_reg = regex.build_optimize("^([A-Z]+) ([^ ?]+)(?:\\?([^ ]*))? HTTP/([0-9.]+)$")
136109
var request_header_reg = regex.build_optimize("^([^:]*): ?(.*)$")
137110
namespace state_codes
138111
constant code_200 = "200 OK"
139112
constant code_400 = "400 Bad Request"
140-
constant code_431 = "431 Request Header Fields Too Large"
141113
constant code_403 = "403 Forbidden"
142114
constant code_404 = "404 Not Found"
143115
constant code_408 = "408 Request Timeout"
116+
constant code_431 = "431 Request Header Fields Too Large"
144117
constant code_500 = "500 Internal Server Error"
118+
constant code_502 = "502 Bad Gateway"
145119
constant code_503 = "503 Service Unavailable"
146120
constant code_eof = "000 End of file"
147121
end
122+
constant status_code_map = {200 : state_codes.code_200, 400 : state_codes.code_400, 403 : state_codes.code_403, 404 : state_codes.code_404, 408 : state_codes.code_408, 431 : state_codes.code_431, 500 : state_codes.code_500, 502 : state_codes.code_502, 503 : state_codes.code_503, 0 : state_codes.code_eof}.to_hash_map()
148123
var wday_map = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}
149124
var mon_map = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
150125
function time_padding(obj, width)
@@ -164,6 +139,10 @@ end
164139
function compose_response(code)
165140
return "HTTP/1.1 " + code + "\r\n" + "Connection: close\r\n" + "Content-Length: 0\r\n\r\n"
166141
end
142+
function send_error_response(sock, code)
143+
var state = async.write(sock, compose_response(code))
144+
state.wait()
145+
end
167146
var log_stream = null
168147
function log(msg)
169148
if log_stream != null
@@ -538,16 +517,14 @@ function read_http_header(sock, state, keep_alive_timeout)
538517
end
539518
if error_code != null
540519
if error_code != state_codes.code_eof
541-
var err_state = async.write(sock, compose_response(error_code))
542-
err_state.wait()
520+
send_error_response(sock, error_code)
543521
end
544522
return null
545523
end
546524
var session = create_http_session(header)
547525
if session == null
548526
log("Parse request header error.")
549-
var err_state = async.write(sock, compose_response(state_codes.code_400))
550-
err_state.wait()
527+
send_error_response(sock, state_codes.code_400)
551528
return null
552529
end
553530
log("Received: Method = " + session.method + ", URL = " + session.url + ", Host = " + session.host + ", Connection = " + session.connection)
@@ -584,8 +561,7 @@ function read_http_header(sock, state, keep_alive_timeout)
584561
end
585562
if error_code != null
586563
if error_code != state_codes.code_eof
587-
var err_state = async.write(sock, compose_response(error_code))
588-
err_state.wait()
564+
send_error_response(sock, error_code)
589565
end
590566
return null
591567
end
@@ -659,8 +635,7 @@ function call_http_handler(session, server)
659635
if server->url_map.exist(error_code)
660636
server->url_map[error_code](*server, session)
661637
else
662-
var err_state = async.write(session.sock, compose_response(error_code))
663-
err_state.wait()
638+
send_error_response(session.sock, error_code)
664639
end
665640
return false
666641
else
@@ -696,8 +671,7 @@ function simple_worker(self)
696671
end
697672
if ++request_count > self->server->max_keep_alive
698673
log("Keep-alive exceeded max request count.")
699-
var err_state = async.write(sock, compose_response(state_codes.code_408))
700-
err_state.wait()
674+
send_error_response(sock, state_codes.code_408)
701675
break
702676
end
703677
var session = read_http_header(sock, read_state, last_request_time + self->server->keep_alive_timeout)
@@ -903,8 +877,7 @@ function master_response_worker(self)
903877
end
904878
if conn->request_queue.empty() && !conn->keep_alive
905879
if !conn->close
906-
var err_state = async.write(conn->sock, compose_response(state_codes.code_408))
907-
err_state.wait()
880+
send_error_response(conn->sock, state_codes.code_408)
908881
end
909882
if !conn->sock.safe_shutdown()
910883
log("safe_shutdown returned false — async jobs may still be pending")
@@ -1613,6 +1586,7 @@ class http_client
16131586
end
16141587
end
16151588
var meta = null
1589+
var interim_count = 0
16161590
loop
16171591
var headers_raw = read_until_limited("\r\n\r\n", http_max_header_size)
16181592
if headers_raw == null
@@ -1633,6 +1607,12 @@ class http_client
16331607
close()
16341608
return null
16351609
end
1610+
++interim_count
1611+
if interim_count > 10
1612+
log("HTTP too many 1xx interim responses, aborting.")
1613+
close()
1614+
return null
1615+
end
16361616
continue
16371617
end
16381618
break

0 commit comments

Comments
 (0)