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 middleware::logger::custom_response_replace #2631

Merged
merged 13 commits into from
Sep 26, 2022

Conversation

benny-n
Copy link
Contributor

@benny-n benny-n commented Feb 5, 2022

PR Type

Feature

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the latest stable rustfmt.
  • (Team) Label with affected crates and semver status.

Overview

It is now possible to pass a closure to the logger, which recevies a StatusCode ServiceResponse and returns a String for use in the log line

Closes #2627

@robjtede robjtede added this to the actix-web post-v4 milestone Feb 8, 2022
@robjtede robjtede removed this from the actix-web post-v4 milestone Mar 1, 2022
@robjtede robjtede added this to the actix-web v4.3 milestone Sep 25, 2022
@robjtede robjtede added B-semver-minor A-web project: actix-web labels Sep 25, 2022
@robjtede
Copy link
Member

robjtede commented Sep 26, 2022

I figured out a way to execute the original plan of custom response-based replacements.

@benny-n let me know what you think of the solution.

@benny-n
Copy link
Contributor Author

benny-n commented Sep 26, 2022

Hi @robjtede,
This is really great!
With these changes we can access a ServiceResponse in the custom function which is what I wanted in the original plan.
So if I understood correctly, the solution was to reconstruct the response into a temporary ServiceResponse without the actual body?

@robjtede
Copy link
Member

@benny-n Yeah, you got it. It works out okay because response bodies are not accessible with only shared refs so it doesn't matter what is in the body slot for our closure here. This way keeps the API free of generics.

@robjtede robjtede changed the title add middleware::logger::custom_status_replace add middleware::logger::custom_response_replace Sep 26, 2022
@robjtede robjtede enabled auto-merge (squash) September 26, 2022 18:36
@robjtede robjtede merged commit ad7e67f into actix:master Sep 26, 2022
@benny-n benny-n deleted the logger-custom-response-replace branch September 27, 2022 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-web project: actix-web B-semver-minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: add middleware::logger::custom_response_replace
2 participants