Comments (11)
In WebAssembly applications with JsValue
, Runtime
is !Send
; in pure Rust applications, Runtime
is Send
.
We may consider using the conditional compilation in Rust (like pre-defined macro in C++), and declare Runtime
, Fetcher
, Signer
as !Send
only when the wasm
feature is enabled in sxg-rs
(like this).
from sxg-rs.
Of the available libraries for implementing a reverse proxy, hyper-reverse-proxy seems like the most accurate (removing hop-by-hop headers including those in Connection
, etc.). It's built on top of Hyper so it supports a bunch of things (notably, streamed responses).
We should also set X-Forwarded-Host
, Forwarded: host=
, and Via
in outgoing requests; not done by that lib.
We'll need some storage/sync mechanism for ACME & OCSP.
We could use routerify for the non-proxied URLs (cert-chain+cbor and validity), but we'll need to test well that it avoids inner URL != outer URL bugs that plagued several Go routers. Alternatively, we could build our own simple router using something like RegexSet or trie_rs
Alternatives considered include:
from sxg-rs.
Another server exists in playground/
but it would take more effort to productionize (e.g. add all the above + the features in hyper-reverse-proxy), and it would add node as a dependency. Would be nice to have something that runs in Rust only.
from sxg-rs.
To start with, I'll implement it with file storage, for the basic "run a server on a VM" case.
I split off #276 for Google Cloud Run support.
from sxg-rs.
@antiphoton @quangIO It appears hyper requires async fns to implement Send
for multithreading (see details). SxgWorker fns do not implement Send
for a variety of reasons.
js_sys
doesn't implementSend
.dyn
doesn't implementSend
unless specified (dyn Foo + Send
) -- which would breakjs_sys
support.- Probably more reasons.
Options to solve this:
block_on()
SxgWorker fns. Presumably this eliminates parallelism -- perhaps that's OK for computations that aren't I/O bound?- Remove
dyn
from the code base; use type parameters instead. Simplest conceptually, but adds line noise and brittleness -- whenever we add a new type parameter, we have to update all callers. - Change types like
Runtime
to traits withSend
and non-Send
impls. Least line noise, but a bit of duplication.
I'm leaning towards 3 where possible, falling back to 2 for less pervasive types. However, I'm not an expert in Rust. Would appreciate your opinions. It seems @quangIO was considering 2 in #278; what are the implications for WasmWorker?
from sxg-rs.
js_sys::Fucntion
does not implement Send
, hence Fetcher
, Signer
, and Storage
do not implement Send
, hence struct Runtime
does not implement Send
.
Box<dyn Fetcher>
, Arc<dyn Fetcher>
and Arc<F: Fetcher>
can't implement Send
as long as Fetcher
does not implement Send
.
I would suggest constructing Runtime
inside hyper
's handler function, so that the Runtime
no longer need to be sent between threads.
from sxg-rs.
I would suggest constructing
Runtime
insidehyper
's handler function, so that theRuntime
no longer need to be sent between threads.
I'm already attempting to construct it inside the closure passed to service_fn
, and that's resulting in the "Future is not Send" error [1]. I'm not positive, but I believe the multithreading runtime needs each individual task to implement Send
because it reserves the right to reschedule it on a different thread; see Tokio docs.
[1] In particular, it's not the call to service_fn
but to server::Builder::serve
that triggers the error.
from sxg-rs.
I'll give it another day of effort, but if that fails, I may just try spawn_blocking
and test that it can handle concurrent requests. I note that warp calls the handler synchronously and warp probably knows what it's doing.
I found myself wanting for language features:
- Constraint kinds so I didn't have to duplicate code between
RuntimeSend
andRuntimeNoSend
impls. - Type-changing struct update since our tests use the struct update syntax quite heavily, but that won't work if we get rid of
dyn
.
from sxg-rs.
Oh, really good idea.
from sxg-rs.
TODO: Refactor this pattern from #314 into a macro in utils:
#[cfg_attr(feature = "wasm", async_trait(?Send))]
#[cfg_attr(not(feature = "wasm"), async_trait)]
from sxg-rs.
Abandoning the attribute macro idea, as the maintenance overhead is not worth the benefit. It would require an additional proc-macro
crate.
from sxg-rs.
Related Issues (20)
- Add signed_host config param
- Lower SXG q-value for outgoing Accept header
- Flaky ACME integration test HOT 1
- Header integrity fetcher should not prefer SXG for subresources
- Current implementation will strip headers with same key HOT 2
- Content-Length header after transformation
- Add AWS Lambda binding
- Add Netlify binding
- Add Vercel binding HOT 2
- Add Google Cloud Run binding
- Add Akamai binding HOT 11
- Remove wasm feature
- Switch Fastly ACME state to use Object Store
- Fastly: proxy unsigned on error
- Add backend_host config param
- Error out if `via: sxgrs`
- Add User-Agent sniffing HOT 6
- Set outer cache-control header
- Enable conditional responses HOT 2
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 sxg-rs.