-
-
Notifications
You must be signed in to change notification settings - Fork 319
feat: Allow websocket subscription with PAK/PAT #3203
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
Open
JanCizmar
wants to merge
11
commits into
main
Choose a base branch
from
jancizmar/ws-with-api-key
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2ace809
feat: Allow websocket subscription with PAK/PAT
JanCizmar 53d880b
feat: Client caching support in export Controllers
JanCizmar 6d55625
chore: lint
JanCizmar c87ceab
chore: refactor the tests
JanCizmar 964bc7b
chore: fix tests
JanCizmar f441448
fix: after rebase authentication stuff
JanCizmar 5acab15
chore: KtLint
JanCizmar aeeecc6
chore: self-CR fixes
JanCizmar 4270697
chore: CodeRabbit fixes
JanCizmar 3e8aecd
feat: Support e-tag, custom implementation supporting modifying methods.
JanCizmar a5327d5
fix: CR Issue, small refactorings in the SecurityService
JanCizmar 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
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
74 changes: 74 additions & 0 deletions
74
backend/api/src/main/kotlin/io/tolgee/component/ProjectLastModifiedManager.kt
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,74 @@ | ||
| package io.tolgee.component | ||
|
|
||
| import io.tolgee.security.ProjectHolder | ||
| import org.springframework.http.CacheControl | ||
| import org.springframework.http.ResponseEntity | ||
| import org.springframework.stereotype.Component | ||
| import org.springframework.web.context.request.WebRequest | ||
| import java.util.concurrent.TimeUnit | ||
|
|
||
| /** | ||
| * Component responsible for managing HTTP conditional requests based on project data modifications. | ||
| * | ||
| * This manager implements the HTTP conditional request mechanism (If-Modified-Since/Last-Modified headers) | ||
| * to enable efficient caching of project-related data. It helps reduce unnecessary data transfer and | ||
| * processing by allowing clients to cache responses and only receive new data when the project has | ||
| * actually been modified. | ||
| */ | ||
| @Component | ||
| class ProjectLastModifiedManager( | ||
| private val projectTranslationLastModifiedManager: ProjectTranslationLastModifiedManager, | ||
| private val projectHolder: ProjectHolder, | ||
| ) { | ||
| /** | ||
| * Executes a function only when the project data has been modified since the client's last request. | ||
| * | ||
| * This method implements HTTP conditional request handling by: | ||
| * 1. Retrieving the last modification timestamp of the current project | ||
| * 2. Checking if the client's If-Modified-Since header indicates the data is still current | ||
| * 3. If data hasn't changed, returning null | ||
| * (which translates to HTTP 304 Not Modified / or HTTP 412 when the method is POST) | ||
| * 4. If data has changed, executing the provided function and wrapping the result in a ResponseEntity | ||
| * with appropriate cache control headers | ||
| * | ||
| * The response includes: | ||
| * - Last-Modified header set to the project's modification timestamp | ||
| * - Cache-Control header set to max-age=0 to ensure validation on each request | ||
| * | ||
| * This mechanism helps optimize performance by preventing export data computation and loading from the database when | ||
| * not modified. | ||
JanCizmar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| */ | ||
| fun <T> onlyWhenProjectDataChanged( | ||
| request: WebRequest, | ||
| fn: ( | ||
| /** | ||
| * Enables setting of additional headers on the response. | ||
| */ | ||
| headersBuilder: ResponseEntity.HeadersBuilder<*>, | ||
| ) -> T?, | ||
| ): ResponseEntity<T>? { | ||
| val lastModified: Long = projectTranslationLastModifiedManager.getLastModified(projectHolder.project.id) | ||
|
|
||
| if (request.checkNotModified(lastModified)) { | ||
| return null | ||
| } | ||
|
|
||
| val headersBuilder = | ||
| ResponseEntity | ||
| .ok() | ||
| .lastModified(lastModified) | ||
| .cacheControl(DEFAULT_CACHE_CONTROL_HEADER) | ||
|
|
||
| val response = fn(headersBuilder) | ||
|
|
||
| return headersBuilder | ||
| .body( | ||
| response, | ||
| ) | ||
| } | ||
|
|
||
| companion object { | ||
| val DEFAULT_CACHE_CONTROL_HEADER = CacheControl.maxAge(0, TimeUnit.SECONDS) | ||
| } | ||
| } | ||
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
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.