Skip to content

Commit

Permalink
misc: code cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: He Xian <[email protected]>
  • Loading branch information
hexian000 committed Nov 10, 2024
1 parent 3a8f374 commit d698a99
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
7 changes: 3 additions & 4 deletions example/ruleset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ _G.redirect = {
-- _G.redirect6: handle IPv6 requests in "[ipv6]:port"
_G.redirect6 = {
-- redirect TCP DNS to local cache
{ match.exact("[2606:4700:4700::1111]:53"), rule.redirect("127.0.0.53:53") },
{ match.exact("[2606:4700:4700::1001]:53"), rule.redirect("127.0.0.53:53") },
{ match.port(53), rule.redirect("127.0.0.53:53") },
-- global condition
{ is_disabled, rule.reject(), "off" },
{ is_disabled, rule.reject(), "off" },
-- go to _G.route6
}

Expand All @@ -87,7 +86,7 @@ _G.hosts = {
-- jump to region2 through region1 proxy
local proxy_region2 = rule.proxy("socks4a://192.168.32.1:1080", "socks4a://192.168.33.1:1080")

-- 3. _G.route*: handle requests by IP address (faster subnet matching)
-- 3. _G.route*: Handle requests by IP address (to match subnet efficiently)
_G.route = {
-- reject loopback or link-local
{ inet.subnet("127.0.0.0/8"), rule.reject() },
Expand Down
5 changes: 2 additions & 3 deletions example/ruleset_simple.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ _G.redirect = {
-- _G.redirect6: handle IPv6 requests in "[ipv6]:port"
_G.redirect6 = {
-- redirect TCP DNS to local cache
{ match.exact("[2606:4700:4700::1111]:53"), rule.redirect("127.0.0.53:53") },
{ match.exact("[2606:4700:4700::1001]:53"), rule.redirect("127.0.0.53:53") },
{ match.port(53), rule.redirect("127.0.0.53:53") },
-- go to _G.route6
}

Expand All @@ -44,7 +43,7 @@ _G.hosts = {
["site1.lan"] = "192.168.1.100",
}

-- 3. _G.route*: handle requests by IP address (faster subnet matching)
-- 3. _G.route*: Handle requests by IP address (to match subnet efficiently)
_G.route = {
-- reject loopback or link-local
{ inet.subnet("127.0.0.0/8"), rule.reject() },
Expand Down
4 changes: 3 additions & 1 deletion src/dialer.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ static bool dialer_send(
CONSTSTRLEN("Proxy-Authorization: Basic ") + 685 + \
CONSTSTRLEN("\r\n") + CONSTSTRLEN("\r\n"))

#define HTTP_RSP_MINLEN (CONSTSTRLEN("HTTP/2 200 \r\n\r\n"))

/* RFC 7231: 4.3.6. CONNECT */
static bool send_http_req(
struct dialer *restrict d, const struct proxyreq *proxy,
Expand Down Expand Up @@ -523,7 +525,7 @@ static bool send_http_req(
if (!dialer_send(d, (unsigned char *)buf, (size_t)(b - buf))) {
return false;
}
socket_rcvlowat(d->w_socket.fd, CONSTSTRLEN("HTTP/2 200 \r\n\r\n"));
socket_rcvlowat(d->w_socket.fd, HTTP_RSP_MINLEN);
return true;
}

Expand Down

0 comments on commit d698a99

Please sign in to comment.