-
Notifications
You must be signed in to change notification settings - Fork 42
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
is it easy to show an example of using websocket with http2 and http3 together? #979
Comments
There is no websocket over http/3 in existing other than some potential RFC draft. If you need an alternative you can look into WebTransport in general use xitca_http::HttpServiceBuilder;
use xitca_web::{handler::handler_service, route::get, App, service::ServiceExt};
fn main() -> std::io::Result<()> {
let service = App::new()
.at("/", get(handler_service(|| async { "" })))
.finish() // explicit finish app composing.
.enclosed(HttpServiceBuilder::new()); // apply http layer middleware to app.
// use xitca-server to run the composed app service with given http middleware.
xitca_server::Builder::new()
.bind("xitca-web", "localhost:8080", service)?
.build()
.wait()
} In other word |
@ouvaa for the question of [dependencies]
xitca-http = { version = "0.4", features = ["router"] }
xitca-server ="0.2"
xitca-service = "0.1"
use std::convert::Infallible;
use xitca_http::{
body::RequestBody,
http::{Request, RequestExt, Response},
util::service::{route::get, Router},
HttpServiceBuilder, ResponseBody,
};
use xitca_service::{fn_service, ServiceExt};
fn main() -> std::io::Result<()> {
let service = Router::new()
.insert("/", get(fn_service(handler)))
.enclosed(HttpServiceBuilder::new());
xitca_server::Builder::new()
.bind("xitca-http", "localhost:8080", service)?
.build()
.wait()
}
async fn handler(
_: Request<RequestExt<RequestBody>>,
) -> Result<Response<ResponseBody>, Infallible> {
Ok(Response::new(ResponseBody::empty()))
} |
@fakeshadow
|
@fakeshadow i'm new to websocket i thought it's supposed to do ws:// ... anyway, how to have it do it in http2 then? can you show the example code in full? if you show it here, it'll be easier for chatgpt to help out. currently chatgpt is hallucinating a lot with xitca implementation. |
I recall already told you how. You can just take this example and add
It's just one line change to That said typical off the shelf http2 client would have problem to handle clear text http2 so in most case you would have to enable tls to make them work too. |
It seems you are missing the point of the example you are referencing. The multi service example is to show case how you can bind multiple services on multiple ports of your host with different service types. It's not necessary what you have to do to handle multiple http protocols. The example showed in #979 (comment) can be used to handle http/1,http/2 and http/3 automatically with correct configuration. |
@fakeshadow can you just show how to handle just http/2 and http/3 automatically with the correct configuration? pls just provide the "practical" normal example that people will use daily. it's quite confusing with the http2/http3 example
|
The point of |
I'll go ahead close this issue as #979 (comment) can seen as the answer. For further read please reference the following: Line 12 in 597f0a4
If you need tls Line 170 in 597f0a4
If you want to bind to both TCP and UDP xitca-web/server/src/builder.rs Line 238 in 597f0a4
|
@fakeshadow it seems quite difficult to fuse / interface websocket and http2/3 together.
can you help provide an example whereby i can combine them for both?
i cant wrap my head around using xitca web and xitca server together. i'm new to rust.
p.s. : i'm learning rust etc and do mention how i can help contribute to this proj. thx
The text was updated successfully, but these errors were encountered: