http - Golang ListenAndServeTLS 在浏览器中不使用 https 时返回数据

标签 http ssl https go

以下是我的 tls 后端:

package main

import (
    "fmt"
    "net/http"
)

const (
    PORT       = ":8443"
    PRIV_KEY   = "./private_key"
    PUBLIC_KEY = "./public_key"
)

func rootHander(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Nobody should read this.")
}

func main() {
    http.HandleFunc("/", rootHander)
    err := http.ListenAndServeTLS(PORT, PUBLIC_KEY, PRIV_KEY, nil)
    if err != nil {
        fmt.Printf("main(): %s\n", err)
    }
}

使用以下两行生成 key :

openssl genrsa -out private_key 2048
openssl req -new -x509 -key private_key -out public_key -days 365

当我启动 tls 服务器并使用浏览器 (https://example.com:8443) 访问该站点时,我得到了预期的结果, 忽略了浏览器警告:

Nobody should read this.

到目前为止一切都很酷。

现在,当我将浏览器指向 http://example.com:8443 时(注意使用的是 http,不是 https)我得到了 Firfox 的以下结果(Chrome 也这样做,但下载了网站):

using http

问题:为什么会有问号?

最佳答案

如果将输出通过管道传输到 od,curl -k -3 http://localhost:8443 | od -A n -t x1,您会得到以下字节序列 15 03 01 00 02 02 0a 由浏览器呈现/处理。

根据https://code.google.com/p/go/issues/detail?id=2253 , 是 TLS 表示“我不明白你说什么”。

关于http - Golang ListenAndServeTLS 在浏览器中不使用 https 时返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23494082/

相关文章:

rest - "resource will never be available in this case"的状态码

ssl - Cookie 在我网站上的 HTTPS 页面上不起作用 (C#)

apache - htaccess 中 http 到 https 重定向的异常

java - 在由 docker 拉取的 Spring Boot 应用程序中实现 LetsEncrypt

java - 确保收到 `response.getOutputStream().write()`

java - Spring MVC 文件名编码错误

javascript - 在 Node.JS 中获取 http post 表单数据

ssl - 为 SSL 指定端口时 Gitlab 不响应

ruby - 通过 API 撤销证书

c - SSL_do_handshake() 卡住了