mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
Strict visibility for Net functions
This commit is contained in:
34
src/Net.zig
34
src/Net.zig
@@ -33,7 +33,7 @@ const assert = @import("lightpanda").assert;
|
|||||||
pub const ENABLE_DEBUG = false;
|
pub const ENABLE_DEBUG = false;
|
||||||
const IS_DEBUG = builtin.mode == .Debug;
|
const IS_DEBUG = builtin.mode == .Debug;
|
||||||
|
|
||||||
pub const Error = error{
|
const Error = error{
|
||||||
UnsupportedProtocol,
|
UnsupportedProtocol,
|
||||||
FailedInit,
|
FailedInit,
|
||||||
UrlMalformat,
|
UrlMalformat,
|
||||||
@@ -122,7 +122,7 @@ pub const Error = error{
|
|||||||
Unknown,
|
Unknown,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn fromCode(code: c.CURLcode) Error {
|
fn errorFromCode(code: c.CURLcode) Error {
|
||||||
if (comptime IS_DEBUG) {
|
if (comptime IS_DEBUG) {
|
||||||
std.debug.assert(code != c.CURLE_OK);
|
std.debug.assert(code != c.CURLE_OK);
|
||||||
}
|
}
|
||||||
@@ -217,7 +217,7 @@ pub fn fromCode(code: c.CURLcode) Error {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const ErrorMulti = error{
|
const ErrorMulti = error{
|
||||||
BadHandle,
|
BadHandle,
|
||||||
BadEasyHandle,
|
BadEasyHandle,
|
||||||
OutOfMemory,
|
OutOfMemory,
|
||||||
@@ -233,7 +233,7 @@ pub const ErrorMulti = error{
|
|||||||
Unknown,
|
Unknown,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn fromMCode(code: c.CURLMcode) ErrorMulti {
|
fn errorMFromCode(code: c.CURLMcode) ErrorMulti {
|
||||||
if (comptime IS_DEBUG) {
|
if (comptime IS_DEBUG) {
|
||||||
std.debug.assert(code != c.CURLM_OK);
|
std.debug.assert(code != c.CURLM_OK);
|
||||||
}
|
}
|
||||||
@@ -255,21 +255,21 @@ fn fromMCode(code: c.CURLMcode) ErrorMulti {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn errorCheck(code: c.CURLcode) Error!void {
|
fn errorCheck(code: c.CURLcode) Error!void {
|
||||||
if (code == c.CURLE_OK) {
|
if (code == c.CURLE_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return fromCode(code);
|
return errorFromCode(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn errorMCheck(code: c.CURLMcode) ErrorMulti!void {
|
fn errorMCheck(code: c.CURLMcode) ErrorMulti!void {
|
||||||
if (code == c.CURLM_OK) {
|
if (code == c.CURLM_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (code == c.CURLM_CALL_MULTI_PERFORM) {
|
if (code == c.CURLM_CALL_MULTI_PERFORM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return fromMCode(code);
|
return errorMFromCode(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const Method = enum(u8) {
|
pub const Method = enum(u8) {
|
||||||
@@ -316,7 +316,7 @@ pub const Headers = struct {
|
|||||||
self.headers = updated_headers;
|
self.headers = updated_headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parseHeader(header_str: []const u8) ?Header {
|
fn parseHeader(header_str: []const u8) ?Header {
|
||||||
const colon_pos = std.mem.indexOfScalar(u8, header_str, ':') orelse return null;
|
const colon_pos = std.mem.indexOfScalar(u8, header_str, ':') orelse return null;
|
||||||
|
|
||||||
const name = std.mem.trim(u8, header_str[0..colon_pos], " \t");
|
const name = std.mem.trim(u8, header_str[0..colon_pos], " \t");
|
||||||
@@ -394,7 +394,7 @@ pub const HeaderIterator = union(enum) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const HeaderValue = struct {
|
const HeaderValue = struct {
|
||||||
value: []const u8,
|
value: []const u8,
|
||||||
amount: usize,
|
amount: usize,
|
||||||
};
|
};
|
||||||
@@ -667,7 +667,7 @@ pub const Connection = struct {
|
|||||||
}
|
}
|
||||||
log.err(.http, "get response header", .{
|
log.err(.http, "get response header", .{
|
||||||
.name = name,
|
.name = name,
|
||||||
.err = fromCode(result),
|
.err = errorFromCode(result),
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -911,7 +911,7 @@ const backend_supports_vectors = switch (builtin.zig_backend) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Websocket messages from client->server are masked using a 4 byte XOR mask
|
// Websocket messages from client->server are masked using a 4 byte XOR mask
|
||||||
pub fn mask(m: []const u8, payload: []u8) void {
|
fn mask(m: []const u8, payload: []u8) void {
|
||||||
var data = payload;
|
var data = payload;
|
||||||
|
|
||||||
if (!comptime backend_supports_vectors) return simpleMask(m, data);
|
if (!comptime backend_supports_vectors) return simpleMask(m, data);
|
||||||
@@ -957,13 +957,13 @@ pub const Message = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// These are the only websocket types that we're currently sending
|
// These are the only websocket types that we're currently sending
|
||||||
pub const OpCode = enum(u8) {
|
const OpCode = enum(u8) {
|
||||||
text = 128 | 1,
|
text = 128 | 1,
|
||||||
close = 128 | 8,
|
close = 128 | 8,
|
||||||
pong = 128 | 10,
|
pong = 128 | 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn fillWebsocketHeader(buf: std.ArrayList(u8)) []const u8 {
|
fn fillWebsocketHeader(buf: std.ArrayList(u8)) []const u8 {
|
||||||
// can't use buf[0..10] here, because the header length
|
// can't use buf[0..10] here, because the header length
|
||||||
// is variable. If it's just 2 bytes, for example, we need the
|
// is variable. If it's just 2 bytes, for example, we need the
|
||||||
// framed message to be:
|
// framed message to be:
|
||||||
@@ -984,7 +984,7 @@ pub fn fillWebsocketHeader(buf: std.ArrayList(u8)) []const u8 {
|
|||||||
|
|
||||||
// makes the assumption that our caller reserved the first
|
// makes the assumption that our caller reserved the first
|
||||||
// 10 bytes for the header
|
// 10 bytes for the header
|
||||||
pub fn websocketHeader(buf: []u8, op_code: OpCode, payload_len: usize) []const u8 {
|
fn websocketHeader(buf: []u8, op_code: OpCode, payload_len: usize) []const u8 {
|
||||||
assert(buf.len == 10, "Websocket.Header", .{ .len = buf.len });
|
assert(buf.len == 10, "Websocket.Header", .{ .len = buf.len });
|
||||||
|
|
||||||
const len = payload_len;
|
const len = payload_len;
|
||||||
@@ -1241,7 +1241,7 @@ pub fn Reader(comptime EXPECT_MASK: bool) type {
|
|||||||
// 3 - We have part of the next message, but either it won't fight into the
|
// 3 - We have part of the next message, but either it won't fight into the
|
||||||
// remaining buffer, or we don't know (because we don't have enough
|
// remaining buffer, or we don't know (because we don't have enough
|
||||||
// of the header to tell the length). We need to "compact" the buffer
|
// of the header to tell the length). We need to "compact" the buffer
|
||||||
pub fn compact(self: *Self) void {
|
fn compact(self: *Self) void {
|
||||||
const pos = self.pos;
|
const pos = self.pos;
|
||||||
const len = self.len;
|
const len = self.len;
|
||||||
|
|
||||||
@@ -1373,7 +1373,7 @@ pub const WsConnection = struct {
|
|||||||
|
|
||||||
const EMPTY_PONG = [_]u8{ 138, 0 };
|
const EMPTY_PONG = [_]u8{ 138, 0 };
|
||||||
|
|
||||||
pub fn sendPong(self: *WsConnection, data: []const u8) !void {
|
fn sendPong(self: *WsConnection, data: []const u8) !void {
|
||||||
if (data.len == 0) {
|
if (data.len == 0) {
|
||||||
return self.send(&EMPTY_PONG);
|
return self.send(&EMPTY_PONG);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,9 +38,6 @@ const ArenaAllocator = std.heap.ArenaAllocator;
|
|||||||
|
|
||||||
const IS_DEBUG = builtin.mode == .Debug;
|
const IS_DEBUG = builtin.mode == .Debug;
|
||||||
|
|
||||||
const errorCheck = Net.errorCheck;
|
|
||||||
const errorMCheck = Net.errorMCheck;
|
|
||||||
|
|
||||||
const Method = Net.Method;
|
const Method = Net.Method;
|
||||||
const ResponseHead = Net.ResponseHead;
|
const ResponseHead = Net.ResponseHead;
|
||||||
const HeaderIterator = Net.HeaderIterator;
|
const HeaderIterator = Net.HeaderIterator;
|
||||||
|
|||||||
Reference in New Issue
Block a user