Skip to content

Conversation

@granuels
Copy link

@granuels granuels commented Dec 13, 2025

Introduce req.last_event_id to provide convenient access to the Last-Event-ID header. Closes #2580.

Summary of Changes

I added req.last_event_id to the Request class to make it easier to access the Last-Event-ID header, which is standard for Server-Sent Events. This implementation uses _header_property helper in both WSGI and ASGI files for performance and consistency. I've also included the necessary tests and a newsfragment.

Related Issues

Closes #2580

Pull Request Checklist

This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. Reading our contribution guide at least once will save you a few review cycles!

If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.

  • Applied changes to both WSGI and ASGI code paths and interfaces (where applicable).
  • Added tests for changed code.
  • Performed automated tests and code quality checks by running tox.
  • Prefixed code comments with GitHub nick and an appropriate prefix.
  • Coding style is consistent with the rest of the framework.
  • Updated documentation for changed code.
    • Added docstrings for any new classes, functions, or modules.
    • Updated docstrings for any modifications to existing code.
    • Updated both WSGI and ASGI docs (where applicable).
    • Added references to new classes, functions, or modules to the relevant RST file under docs/.
    • Updated all relevant supporting documentation files under docs/.
    • A copyright notice is included at the top of any new modules (using your own name or the name of your organization).
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
  • Changes (and possible deprecations) have towncrier news fragments under docs/_newsfragments/, with the file name format {issue_number}.{fragment_type}.rst. (Run tox -e towncrier, and inspect docs/_build/html/changes/ in the browser to ensure it renders correctly.)
  • LLM output, if any, has been carefully reviewed and tested by a human developer. (See also: Use of LLMs ("AI").)

Introduce req.last_event_id to provide convenient access to the Last-Event-ID header. Closes falconry#2580.
@codecov
Copy link

codecov bot commented Dec 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a33301e) to head (2b7fe66).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2587   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           64        64           
  Lines         7866      7869    +3     
  Branches      1078      1078           
=========================================
+ Hits          7866      7869    +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@vytas7 vytas7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks once again for the PR, it looks good for most of it.
I've requested a couple of improvements inline.

Another thing, it seems like the PR summary is heavily influenced by "AI", if not outright churned by Cursor or similar... 👿 Don't do this! It is not the end of the world, but it would be much more useful if you wrote a sentence or two yourself.

This is verbose and prone to typos (e.g., casing issues).

No, the get_header(...) name argument is not case sensitive!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rewrite this more as a story (what has been done), not in imperative (as docstrings)?

str: The value of the Last-Event-ID header, or None if the
header was not present in the request.
"""
return self.get_header('Last-Event-ID')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we optimize this by operating on the internal headers directly?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR summary and optimized the implementation to use _header_property in both WSGI and ASGI files as requested. I also updated the newsfragment to follow the narrative style. Ready for re-review!

@granuels granuels requested a review from vytas7 December 14, 2025 23:05
@vytas7 vytas7 changed the title feat(request): Add last_event_id property feat(request): add last_event_id property Dec 29, 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.

Add new request header property req.last_event_id

2 participants