Skip to content

Commit

Permalink
Add a way to get all keys of the headers. (#131)
Browse files Browse the repository at this point in the history
Fixes #120.
  • Loading branch information
floitsch authored Mar 14, 2024
1 parent a15ed24 commit 0f141e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/headers.toit
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class Headers:

constructor.private_ .headers_:

/**
The keys of the header.
*/
keys -> List:
if not headers_: return []
return headers_.keys

/**
Returns a single string value for the header or null if the header is not
present. If there are multiple values, the last value is returned.
Expand Down
8 changes: 8 additions & 0 deletions tests/headers_test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import http

main:
test_from_map
test_keys

/**
Converts the given $headers to a string.
Expand Down Expand Up @@ -35,3 +36,10 @@ test_from_map:

headers = http.Headers.from_map {"foo": ["bar", "baz"], "Foo": "corge"}
expect_equals "Foo: bar\r\nFoo: baz\r\nFoo: corge\r\n" (stringify headers)

test_keys:
headers := http.Headers.from_map {"foo": ["bar", "baz"], "qux": "quux"}
expect_list_equals ["Foo", "Qux"] headers.keys

headers = http.Headers
expect_list_equals [] headers.keys

0 comments on commit 0f141e0

Please sign in to comment.