Ai
77 Star 124 Fork 105

openEuler/PilotGo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
judgeProtocol.go 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
wubijie 提交于 2024-11-27 20:04 +08:00 . Add copyright information
/*
* Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved.
* PilotGo licensed under the Mulan Permissive Software License, Version 2.
* See LICENSE file for more details.
* Author: Wangjunqi123 <wangjunqi@kylinos.cn>
* Date: Wed Jun 12 14:00:31 2024 +0800
*/
package httputils
import (
"crypto/tls"
"fmt"
"io"
"net"
"net/http"
"net/url"
"strings"
)
func ServerIsHttp(rawurl string) (bool, error) {
url, err := url.Parse(rawurl)
if err != nil {
return false, err
}
url_string := fmt.Sprintf("http://%s", net.JoinHostPort(url.Hostname(), url.Port()))
req, err := http.NewRequest("GET", url_string, nil)
if err != nil {
return false, err
}
hc := &http.Client{
Transport: &http.Transport{
DisableKeepAlives: true,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
}
resp, err := hc.Do(req)
if err != nil {
return false, err
}
defer resp.Body.Close()
respbytes, err := io.ReadAll(resp.Body)
if err != nil {
return false, err
}
if resp.StatusCode != 200 && strings.Contains(string(respbytes), "Client sent an HTTP request to an HTTPS server") {
return false, nil
}
return true, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openeuler/PilotGo.git
git@gitee.com:openeuler/PilotGo.git
openeuler
PilotGo
PilotGo
a82bc8e8fc49

搜索帮助