Comments (6)
So after some noodling, I realized that hyper doesn't actually natively support unix sockets! I had to use hyperlocal in order to get all of the traits on the correct Unix streams.
With that in mind, I thought it easiest to add hyperlocal
as an optional dependency and hide the whole thing behind a feature flag. This means that I actually went with the original solution you proposed @encendre, of implementing another server and ignoring the port. Not the most elegant solution, but will definitely work for now!
from thruster.
Yep, I very much like this functionality. I have a few thoughts about this. It looks to me like tokio models the incoming streams as separate structs. I don't have enough knowledge about why they're doing this, probably because of tcp vs unix data streams, but I bet they have good reasons.
With that in mind, I'd like to propose adding build_on_unix_socket
to the HyperServer
impl for now.
async fn build_on_unix_socket(self, socket_addr: &str);
This could then be used just like start
does with build
internally, that is
let server = HyperServer::new(app);
tokio::runtime::Runtime::new()
.unwrap()
.block_on(server.build_on_unix_socket("/tmp/thruster.sock"))
Thoughts? This seems less invasive than adding it to a trait, and less work than maintaining a third set of ThrusterServer implementations.
from thruster.
I've been thinking about it.
I think a better solution would be to implement a method that allows the application to build on any hyper server configuration.
async fn build_on_hyper_builder(mut self, builder: hyper::server::Builder)
and then we just have to use this new method for writing the build
method required by the ThrusterServer
trait, like this
async fn build(mut self, host: &str, port: u16) {
let addr = (host, port).to_socket_addrs().unwrap().next().unwrap();
let builder = Server::bind(&addr);
self.build_on_hyper_builder(builder);
}
This seems it covers more use cases, is still easy to build on unix socket for my use case
let mut listener = tokio::net::UnixListener::bind("/tmp/thruster.sock").unwrap();
let incoming = listener.incoming();
let incoming = hyper::server::accept::from_stream(incoming);
let builder = Server::builder(incoming);
let server = HyperServer::new(app);
tokio::runtime::Runtime::new()
.unwrap()
.block_on(server.build_on_hyper_builder(builder));
from thruster.
from thruster.
I tried to implement it but since I'm pretty new to rust I didn't succeed.
I have successfully compiled the crate adding the new method with and a few tricks that seem unnatural to me...
But the example I wrote doesn't work.
from thruster.
I can try this out today, not to worry! I'll post the PR here when it's done so you can compare with what you were doing and hopefully see where you were going astray :)
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] Make context.set(header_key, header_value) available to set header HOT 5
- [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.