Comments (5)
Good question(s)!
- For the availability of
set
, have you imported theContext
trait like the error is suggesting? It should be a public trait on any context, includingBasicHyperContext
. - For changing a header, is it enough to remove a header? The
remove
method also exists for headers (see here.) This should let you remove a header, update it to what you want, then add it again. One case that I can imagine this not supporting is if you needed the value previously set by another piece of middleware -- it might make sense to haveremove
return anOption<String>
.
For what you tried, request
is the incoming request, so grabbing any headers (or setting them!) would just affect the incoming side, not the outgoing side.
from thruster.
It's like you were originally asking -- set
and remove
alter the outgoing headers.
Context::set
: https://docs.rs/thruster/1.2.5/thruster/trait.Context.html#tymethod.setContext::remove
: https://docs.rs/thruster/1.2.5/thruster/trait.Context.html#tymethod.remove
You just need to remember to include the Context
trait via use thruster::Context;
from thruster.
So to answer me, import use thruster::Context
allows modifying "outgoing" headers, no need to make "set" public.
from thruster.
For what you tried,
request
is the incoming request, so grabbing any headers (or setting them!) would just affect the incoming side, not the outgoing side.
Please explain to me how to change the outgoing headers 🥺 🙏🏻
from thruster.
I followed your suggestion and its working now:
Thanks for the help @trezm!
from thruster.
Related Issues (20)
- Proposal: Using traits instead of static fn for middleware chains HOT 5
- [Feature] Add ability to shutdown server once it has been started HOT 7
- Smol support? HOT 1
- No readme on crates.io HOT 2
- Add release 1.1.2 on GitHub HOT 1
- middleware tuple compile errors HOT 2
- Get POST body without introducing crash bug? HOT 2
- Trailing slash not checked? HOT 4
- Alias ideas HOT 6
- How to set CORS with thruster? HOT 14
- [FEATURE REQUEST] Add example for parse and validate a JSON body and query params HOT 4
- [FEATURE REQUEST] Easier access to read request headers HOT 3
- [FEATURE REQUEST] Make extended example on generate Context HOT 3
- [FEATURE REQUEST] Easier method to read request params HOT 3
- [REQUEST] Remove Releases and packages from GitHub repos HOT 1
- Incorrect ThrusterError struct definition in error handling docs HOT 1
- external middleware (plugins/libraries) HOT 26
- testing module seems to only have one `request` method HOT 4
- reading cookies/headers from context HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thruster.