Can We Still Use HTTP?

Can We Still Use HTTP?. I recently launched a new service, and a collection interface takes up more bandwidth. This interface is straightforward, and I’m c。

分享
Can We Still Use HTTP?
https://www.cloudflare.com/learning/ssl/why-is-http-not-secure/

I recently launched a new service, and a collection interface takes up more bandwidth. This interface is straightforward, and I’m curious about how much data is transferred in a HTTPS request. Relative to HTTP packets, how much larger?

I wrote a demo to test it.

func helloHandler(w http.ResponseWriter, r *http.Request) {   
    fmt.Fprintf(w, "Hello, World!")   
}   
   
var port int   
   
func init() {   
    flag.IntVar(&port, "port", 8082, "port to listen on")   
    flag.Parse()   
}   
func main() {   
   
    http.HandleFunc("/", helloHandler)   
    fmt.Println(fmt.Sprintf("Starting server at port %d", port))   
    if err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil); err != nil {   
       fmt.Println("Error starting server:", err)   
    }   
}

Then, use caddy locally to provide the https

http://your-domain.com { 
    reverse_proxy 127.0.0.1:8082 
} 
 
https://your-domain.com { 
    reverse_proxy 127.0.0.1:8082 
    tls internal 
}

Finally, grabbing packets with wireshark, I was surprised to find. A simple HTTPS request transfers 2164 bytes of data.

A simple HTTPS request transfers 2164 bytes of data

Assuming concurrency of 500 QPS, the bandwidth required for this interface is:

2164×8×500/1000000 ≈ 8.656Mbps

The full name of HTTPS is HTTP over TLS. Each time a new TCP connection is established, it usually requires a full TLS Handshake. During the handshake, the client and server must exchange information such as certificates, public keys, encryption algorithms, etc; this data takes up more bytes. The main components of a TLS Handshake include:

  • Random numbers for the client and server
  • Supported encryption algorithms and TLS version information
  • Digital certificate of the server (with public key)
  • Pre-Master Secret” for symmetric key generation This process is time-consuming and consumes bandwidth and CPU resources.

Therefore, the crudest solution that comes to mind is relatively simple: use HTTP directly, omitting the TLS Handshake process, and then, naturally, there will be no TLS transmission. 
So, is it effective? Verify it to find out.

http reques

For the same request, the HTTP interface takes only 223 bytes, which is about 1/10th of an HTTP request.

HTTPS is the preferred choice in most cases, providing better security and SEO.

HTTP can be chosen to optimize performance in controlled environments with intranet or high-performance requirements and when transferring non-sensitive data.

Of course, HTTPS can also optimize the TLS Handshake process, which is Keep-Alive. Keep-Alive is a connection multiplexing mechanism that allows multiple request-response interactions over a single TCP connection without creating a new connection for each request. It significantly reduces connection establishment and closure overhead in HTTPS and improves performance.

阅读更多

那些意外变成特性的 Bug:当代码漏洞改写计算史

那些意外变成特性的 Bug:当代码漏洞改写计算史

那些意外变成特性的 Bug:当代码漏洞改写计算史. 比起草台班子将错就错的神话,面对异常数据时的观测定力才是真的 社交网络上常年流传着一类爽文:某家公司的程序员把代码写崩了,结果不仅没被开除,这个 Bug 反而成了拳头产品,妥妥的爽文主角剧本。 最常被搬出来的有三个:Audio Hijack 写错试用期拯救公。

By huizhou92