mirror of
https://github.com/ziex-dev/ziex.git
synced 2026-07-20 02:29:36 -06:00
refactor: rename searchParams to queries
This commit is contained in:
parent
c033764395
commit
56532f7e04
@ -43,7 +43,7 @@ pub fn handleRequest(ctx: zx.PageContext) BenchState {
|
||||
ctx.response.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
||||
ctx.response.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
|
||||
const qs = ctx.request.searchParams;
|
||||
const qs = ctx.request.queries;
|
||||
|
||||
const action = qs.get("action");
|
||||
if (action) |a| {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(ctx: zx.PageCtx(void, AuthState)) zx.Component {
|
||||
const allocator = ctx.arena;
|
||||
const auth = ctx.state;
|
||||
const msg = ctx.request.searchParams.get("msg");
|
||||
const msg = ctx.request.queries.get("msg");
|
||||
|
||||
// Handle login/logout POST actions
|
||||
handleAction(ctx);
|
||||
|
||||
@ -17,7 +17,7 @@ pub fn handleRequest(ctx: zx.PageContext) RequestInfo {
|
||||
// Load from KV synchronously
|
||||
syncFromKv(ctx, &users);
|
||||
|
||||
const qs = ctx.request.searchParams;
|
||||
const qs = ctx.request.queries;
|
||||
|
||||
const is_reset = qs.get("reset") != null;
|
||||
const is_delete = qs.get("delete") != null;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(ctx: zx.PageContext) zx.Component {
|
||||
var chat_username = ctx.request.cookies.get("username") orelse "";
|
||||
const set_username = ctx.request.searchParams.get("username") orelse "";
|
||||
var leave_username = ctx.request.searchParams.get("leave") orelse "";
|
||||
const set_username = ctx.request.queries.get("username") orelse "";
|
||||
var leave_username = ctx.request.queries.get("leave") orelse "";
|
||||
if (set_username.len > 0) {
|
||||
ctx.response.cookies.set("username", set_username, .{});
|
||||
chat_username = set_username;
|
||||
|
||||
@ -6,7 +6,7 @@ var remaining_clients = std.atomic.Value(u32).init(CLIENTS_TO_WAIT_FOR);
|
||||
|
||||
pub fn GET(ctx: zx.RouteContext) !void {
|
||||
const current = remaining_clients.load(.monotonic);
|
||||
const name = ctx.request.searchParams.get("name") orelse
|
||||
const name = ctx.request.queries.get("name") orelse
|
||||
std.fmt.allocPrint(ctx.arena, "Client #{d}", .{CLIENTS_TO_WAIT_FOR - current}) catch "Client";
|
||||
|
||||
try ctx.socket.upgrade(SocketData{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(ctx: zx.PageContext) zx.Component {
|
||||
const query = ctx.request.searchParams;
|
||||
const query = ctx.request.queries;
|
||||
|
||||
if (query.get("reset")) |_|
|
||||
count = 0
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(ctx: zx.PageContext) !zx.Component {
|
||||
const query = ctx.request.searchParams;
|
||||
const query = ctx.request.queries;
|
||||
|
||||
if (query.get("reset")) |_|
|
||||
count = 0
|
||||
|
||||
@ -83,10 +83,10 @@ cookies: Cookies = .{ .header_value = "" },
|
||||
/// URL search parameters accessor.
|
||||
///
|
||||
/// **Zig Note:** This is an extension field. In the web standard, you would use
|
||||
/// `new URL(request.url).searchParams` to access search parameters.
|
||||
/// `new URL(request.url).queries` to access search parameters.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
|
||||
searchParams: URLSearchParams = .{},
|
||||
queries: URLSearchParams = .{},
|
||||
|
||||
/// URL parameters accessor (from route matching).
|
||||
///
|
||||
@ -377,7 +377,7 @@ pub const Builder = struct {
|
||||
.vtable = self.headers_vtable,
|
||||
},
|
||||
.cookies = .{ .header_value = self.cookie_header },
|
||||
.searchParams = .{
|
||||
.queries = .{
|
||||
.backend_ctx = self.search_params_ctx,
|
||||
.vtable = self.search_params_vtable,
|
||||
},
|
||||
|
||||
@ -92,7 +92,7 @@ pub fn run() !void {
|
||||
.backend_ctx = @ptrCast(&wasi_headers),
|
||||
.vtable = &WasiHeaders.vtable,
|
||||
},
|
||||
.searchParams = .{
|
||||
.queries = .{
|
||||
.backend_ctx = @ptrCast(&wasi_search),
|
||||
.vtable = &WasiSearchParams.vtable,
|
||||
},
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(ctx: zx.PageContext) !zx.Component {
|
||||
const query = ctx.request.searchParams;
|
||||
const query = ctx.request.queries;
|
||||
|
||||
if (query.get("reset")) |_|
|
||||
count = 0
|
||||
|
||||
@ -2,7 +2,7 @@ pub const options = zx.PageOptions{ .methods = &.{ .GET, .POST } };
|
||||
const Context = @import("../Context.zig");
|
||||
|
||||
pub fn Page(ctx: zx.PageCtx(Context, void)) zx.Component {
|
||||
const query = ctx.request.searchParams;
|
||||
const query = ctx.request.queries;
|
||||
|
||||
count = ctx.app.db.getCount() catch -1;
|
||||
|
||||
|
||||
@ -82,20 +82,20 @@ test "Request.headers: has returns false without backend" {
|
||||
|
||||
// --- URLSearchParams --- //
|
||||
|
||||
test "Request.searchParams: get returns null without backend" {
|
||||
test "Request.queries: get returns null without backend" {
|
||||
var buffer: [1024]u8 = undefined;
|
||||
var fba = std.heap.FixedBufferAllocator.init(&buffer);
|
||||
|
||||
const req = (Request.Builder{ .arena = fba.allocator() }).build();
|
||||
try std.testing.expect(req.searchParams.get("q") == null);
|
||||
try std.testing.expect(req.queries.get("q") == null);
|
||||
}
|
||||
|
||||
test "Request.searchParams: has returns false without backend" {
|
||||
test "Request.queries: has returns false without backend" {
|
||||
var buffer: [1024]u8 = undefined;
|
||||
var fba = std.heap.FixedBufferAllocator.init(&buffer);
|
||||
|
||||
const req = (Request.Builder{ .arena = fba.allocator() }).build();
|
||||
try std.testing.expect(!req.searchParams.has("q"));
|
||||
try std.testing.expect(!req.queries.has("q"));
|
||||
}
|
||||
|
||||
// --- Builder --- //
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user