How do I upgrade an Actix http connection to tcp - http

The hyper crate has a function hyper::upgrade::on(&req) that takes in a request and initializes a connection upgrade to another protocol. I would like to do the same with Actix web. Is this possible? I would highly appreciate any links or description of how I can do this.

Related

Conceptual HTTPS/HTTP question for golang repository

I have a Gateway API that is built with Golang. We use the "net/http" library documented here https://pkg.go.dev/net/http#example-ListenAndServeTLS. This service has HTTPS connection set up. The connections to my ELB’s use HTTPS because I use TLS termination. So this one Gateway API has the ssl cert. But then passes the connection to a regular HTTP connection to the other instances.
In short, the Gateway API has HTTPs support, but the services connected to my Gateway API uses HTTP.
When I check my UI services, It shows that we are using HTTP 1.1 still. However from Golang's documentation the package "net/http" should provide HTTP 2.0 support automatically.
Do I need to upgrade my internal services to use HTTPs instead of HTTP in order to use http 2.0?
Sorry If this post comes off as ignorant or rude. I really appreciate anyone taking there time to read this, and am willing to provide any more information that Is needed.
http2 include h2(TLS) h2c(no TLS), net/http use h2 default when ListenAndServeTLS.
if you use http, net/http not use h2c, but http1.1 currently no browser supports HTTP/2 unencrypted
becase net/http don't support h2c default, if you want use h2c(non-TLS version of HTTP/2):
https://pkg.go.dev/golang.org/x/net#v0.0.0-20220421235706-1d1ef9303861/http2/h2c

Http requests and TCP connections

My understanding so far is that when someone tries to access web page the following happens:
HTTP request is formed
New socket is opened
HTTP request is sent
If everything went OK, the web browser accepts HTTP response and builds DOM tree out of received HTML. If there are any resources missing, new HTTP request needs to be made for each one separately.
Each of those HTTP requests requires opening another socket (establishing new virtual connection with server).
Q: How is that efficient? I understand those resources could be located on another host (which would indeed require new TCP connection) but if they are all on the same host wouldn't it be way more efficient to transfer all data within single TCP connection.
Each of those HTTP requests requires opening another socket (establishing new virtual connection with server).
No it doesn't. HTTP 1.1 uses persistent connections by default, and HTTP 1.0 before it had the unofficial Connection: keep-alive header, which accomplished the same thing, nearly twenty years ago.
Q: How is that efficient?
It isn't, and that's why it doesn't happen.
I understand those resources could be located on another host (which would indeed require new TCP connection) but if they are all on the same host wouldn't it be way more efficient to transfer all data within single TCP connection.
Yes, and that is what happens by default.

How to create a STARTTLS connection in Websockets or AJAX

I would like to know how to create a connection from a client web browser to a server if it support STARTTLS.
SSL/TLS layer involve using a different port. STARTLS aim at making both encrypted/unecrypted version of the protocol availaible on the same port.
Websockets and Ajax are just suggestion. Any working method (like RAW socket API) are accepted.
Your question is quite unclear: why does it mention web browsers and STARTTLS in the same sentence? Probably you are confusing TLS(SSL) with STARTTLS.
Encrypted WebSockets connections are created using the wss: URI scheme:
websocket = new WebSocket('wss://server.com');
And of course encrypted HTTP connections are created using the https: URI scheme in the first place.
STARTTLS is a command which is used to upgrade the connection from clear text to TLS encrypted in some protocols such as SMTP or LDAP.

what is the benefit of using http hijacker

Go http pkg provide a Hijacker interface, can anyone tell when should I use it.
I check the comment, after a Hijack call lets the caller take over the connection, the HTTP server library will not do anything else with the connection.
I understand it as it's used to support both http request and common tcp interactive within one port. Is it right? Does it has any other benefits.
It means that you take over the control of TCP connection.
TCP is a generic transport protocol, whereas HTTP is an application protocol on top of TCP. The OSI seven layer model describes TCP as layer 4 and HTTP is layer 7.
If you need to implement a different application protocol, this is one use-case for hijacking.
Or if you need to do something specialised with HTTP, like preventing keep-alive connections, that is another use-case.
An example for an alternative web application protocol is Google's SPDY. It's also a good reason why you might hijack an existing HTTP connection, rather than create a TCP connection directly. For SPDY, a browser would first make an HTTP request that included 'accept' headers indicating that it is also able to understand SPDY. So now you could hijack the connection and implement SPDY instead of HTTP.

Anyone aware of a simple example of a Netty HTTP server which supports persistent HTTP connections?

Can anyone provide an example of a simple HTTP server implemented using Netty, that supports persistent HTTP connections.
In other words, it won't close the connection until the client closes it, and can receive additional HTTP requests over the same connection?
This is exactly one of the things their sample http code demonstrates.

Resources