Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Set-Cookie parsing #448

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

karlseguin
Copy link
Contributor

This code isn't hooked into anything. It's only a Set-Cookie response header parser (which includes a DateTime parser).

Next step:

  1. Save them in the browser
  2. When sending a request, figure out which cookies should be sent
  3. Include them in the request

I added a testing.zig. I needed a function to assert an integer was within a delta:

test "DateTime: now" {
    const dt = DateTime.now();
    try testing.expectDelta(std.time.microTimestamp(), dt.micros, 1000);
}

std.testing only has this for floats.

It also expands expectEqual to work against strings. I think is nice on its own, but it's particularly useful when testing against an anytype.

fn expectCookieAttributes(attributes: anytype, actual: Cookie) !void {
   inline for (@typeInfo(@TypeOf(attributes)).Struct.fields) |field| {
      testing.expectEqual(@field(anytype, field.name), @field(actual, field.name))
   }
}

This doesn't work with std.expectEqual if any of the values are strings.

@karlseguin karlseguin changed the title Add Set-Cooking parsing Add Set-Cookie parsing Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant