-
Notifications
You must be signed in to change notification settings - Fork 679
Add If-Match header to sample patch endpoints
#6416
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cbffea4
initial commit
j053y dc3c96a
don't send etag back on 412 easy way to cheat the system
j053y 71af200
remove unused
j053y 5254a94
refactor keeping match closer to db
j053y c3e76b2
address PR comments and cleanup save code and refactor tests to accou…
j053y 0d1d1af
check for Etag on success
j053y 13890b1
update last_modified at on if match save
j053y 705ae54
tweaks
j053y dd348e7
use ETag.create
j053y File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| """ | ||
| HTTP utils | ||
| | Copyright 2017-2025, Voxel51, Inc. | ||
| | `voxel51.com <https://voxel51.com/>`_ | ||
| | | ||
| """ | ||
|
|
||
| from typing import Any | ||
|
|
||
|
|
||
| class ETag: | ||
| """Utility class for creating and parsing ETag strings.""" | ||
|
|
||
| @staticmethod | ||
| def create(value: Any) -> str: | ||
|
||
| """Creates an ETag string from the given value.""" | ||
| return f'"{value}"' | ||
|
|
||
| @staticmethod | ||
| def parse(etag: str) -> tuple[str, bool]: | ||
| """Parses an ETag string into its value and whether it is weak.""" | ||
|
|
||
| is_weak = False | ||
| if etag.startswith("W/"): | ||
| is_weak = True | ||
| etag = etag[2:] # Remove "W/" prefix | ||
|
|
||
| # Remove surrounding quotes (ETags are typically quoted) | ||
| if etag.startswith('"') and etag.endswith('"'): | ||
| etag = etag[1:-1] | ||
j053y marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return etag, is_weak | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| """ | ||
|
|
||
| | Copyright 2017-2025, Voxel51, Inc. | ||
| | `voxel51.com <https://voxel51.com/>`_ | ||
| | | ||
| """ | ||
|
|
||
| from typing import Any, Union | ||
| from bson import json_util | ||
|
|
||
| from starlette.responses import JSONResponse as StarletteJSONResponse | ||
|
|
||
| from fiftyone.server.utils.json.encoder import Encoder | ||
| from fiftyone.server.utils.json.jsonpatch import parse as parse_jsonpatch | ||
| from fiftyone.server.utils.json.serialization import deserialize, serialize | ||
|
|
||
|
|
||
| def dumps(obj: Any) -> str: | ||
| """Serializes an object to a JSON-formatted string.""" | ||
| return json_util.dumps(obj, cls=Encoder) | ||
|
|
||
|
|
||
| def loads(s: Union[str, bytes, bytearray, None]) -> Any: | ||
| """Deserializes a JSON-formatted string to a Python object.""" | ||
| return json_util.loads(s) if s else {} | ||
|
|
||
|
|
||
| class JSONResponse(StarletteJSONResponse): | ||
| """Custom JSON response that uses the custom Encoder.""" | ||
|
|
||
| def render(self, content: Any) -> bytes: | ||
| return dumps(content).encode("utf-8") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """ | ||
|
|
||
| | Copyright 2017-2025, Voxel51, Inc. | ||
| | `voxel51.com <https://voxel51.com/>`_ | ||
| | | ||
| """ | ||
|
|
||
| from typing import Any, Union | ||
| import json | ||
|
|
||
| from bson import json_util | ||
| import numpy as np | ||
| from starlette.responses import JSONResponse as StarletteJSONResponse | ||
|
|
||
|
|
||
| class Encoder(json.JSONEncoder): | ||
| """Custom JSON encoder that handles numpy types.""" | ||
|
|
||
| def default(self, o): | ||
| """Override the default method to handle numpy types.""" | ||
|
|
||
| if isinstance(o, np.floating): | ||
| return float(o) | ||
|
|
||
| if isinstance(o, np.integer): | ||
| return int(o) | ||
|
|
||
| return json.JSONEncoder.default(self, o) | ||
|
|
||
|
|
||
| def dumps(obj: Any) -> str: | ||
| """Serializes an object to a JSON-formatted string.""" | ||
| return json_util.dumps(obj, cls=Encoder) | ||
|
|
||
|
|
||
| def loads(s: Union[str, bytes, bytearray, None]) -> Any: | ||
| """Deserializes a JSON-formatted string to a Python object.""" | ||
| return json_util.loads(s) if s else {} | ||
|
|
||
|
|
||
| class JSONResponse(StarletteJSONResponse): | ||
| """Custom JSON response that uses the custom Encoder.""" | ||
|
|
||
| def render(self, content: Any) -> bytes: | ||
| return dumps(content).encode("utf-8") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.