mirror of
https://github.com/luscis/openlan.git
synced 2025-10-19 07:14:32 +08:00
fix: http: connect timeout.
This commit is contained in:
@@ -24,16 +24,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type HttpRecord struct {
|
type HttpRecord struct {
|
||||||
Count int
|
Count int
|
||||||
LastAt string
|
LastAt string
|
||||||
Domain string
|
CreateAt string
|
||||||
|
Domain string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *HttpRecord) Update() {
|
func (r *HttpRecord) Update() {
|
||||||
|
if r.Count == 0 {
|
||||||
|
r.CreateAt = time.Now().Local().String()
|
||||||
|
}
|
||||||
r.Count += 1
|
r.Count += 1
|
||||||
r.LastAt = time.Now().Local().String()
|
r.LastAt = time.Now().Local().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NotFound(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.Error(w, "Oops!", http.StatusNotFound)
|
||||||
|
}
|
||||||
|
|
||||||
type HttpProxy struct {
|
type HttpProxy struct {
|
||||||
pass map[string]string
|
pass map[string]string
|
||||||
out *libol.SubLogger
|
out *libol.SubLogger
|
||||||
@@ -126,11 +134,12 @@ func NewHttpProxy(cfg *co.HttpProxy) *HttpProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *HttpProxy) loadUrl() {
|
func (t *HttpProxy) loadUrl() {
|
||||||
if strings.HasPrefix(t.cfg.Listen, "127.") {
|
if strings.HasPrefix(t.cfg.Listen, "127.0.0.") {
|
||||||
t.api.HandleFunc("/", t.GetStats)
|
t.api.HandleFunc("/", t.GetStats)
|
||||||
t.api.HandleFunc("/config", t.GetConfig)
|
t.api.HandleFunc("/config", t.GetConfig)
|
||||||
t.api.HandleFunc("/pac", t.GetPac)
|
t.api.HandleFunc("/pac", t.GetPac)
|
||||||
}
|
}
|
||||||
|
t.api.NotFoundHandler = http.HandlerFunc(NotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *HttpProxy) loadPass() {
|
func (t *HttpProxy) loadPass() {
|
||||||
@@ -235,9 +244,11 @@ func (t *HttpProxy) openConn(protocol, remote string, insecure bool) (net.Conn,
|
|||||||
conf := &tls.Config{
|
conf := &tls.Config{
|
||||||
InsecureSkipVerify: insecure,
|
InsecureSkipVerify: insecure,
|
||||||
}
|
}
|
||||||
return tls.Dial("tcp", remote, conf)
|
dialer := &net.Dialer{Timeout: 10 * time.Second}
|
||||||
|
return tls.DialWithDialer(dialer, "tcp", remote, conf)
|
||||||
|
|
||||||
}
|
}
|
||||||
return net.Dial("tcp", remote)
|
return net.DialTimeout("tcp", remote, 10*time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *HttpProxy) cloneRequest(r *http.Request, secret string) ([]byte, error) {
|
func (t *HttpProxy) cloneRequest(r *http.Request, secret string) ([]byte, error) {
|
||||||
@@ -445,11 +456,12 @@ var httpTmpl = map[string]string{
|
|||||||
</table>
|
</table>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Domain</td><td>Count</td><td>LastAt</td>
|
<td>Domain</td><td>Count</td><td>LastAt</td><td>CreateAt</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{- range .Requests }}
|
{{- range .Requests }}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ .Domain }}</td><td>{{ .Count }}</td><td>{{ .LastAt }}</td>
|
<td>{{ .Domain }}</td><td>{{ .Count }}</td>
|
||||||
|
<td>{{ .LastAt }}</td><td>{{ .CreateAt }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{- end }}
|
{{- end }}
|
||||||
</table>
|
</table>
|
||||||
@@ -479,9 +491,10 @@ func (t *HttpProxy) GetStats(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
for name, record := range t.requests {
|
for name, record := range t.requests {
|
||||||
data.Requests = append(data.Requests, &HttpRecord{
|
data.Requests = append(data.Requests, &HttpRecord{
|
||||||
Domain: name,
|
Domain: name,
|
||||||
Count: record.Count,
|
Count: record.Count,
|
||||||
LastAt: record.LastAt,
|
LastAt: record.LastAt,
|
||||||
|
CreateAt: record.CreateAt,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,13 +24,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NotFound(w http.ResponseWriter, r *http.Request) {
|
func NotFound(w http.ResponseWriter, r *http.Request) {
|
||||||
libol.Info("NotFound %s %s", r.Method, r.URL.Path)
|
http.Error(w, "Oops!", http.StatusNotFound)
|
||||||
http.Error(w, "oops!!!", http.StatusNotFound)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NotAllowed(w http.ResponseWriter, r *http.Request) {
|
func NotAllowed(w http.ResponseWriter, r *http.Request) {
|
||||||
libol.Info("NotAllowed %s %s", r.Method, r.URL.Path)
|
http.Error(w, "Oops!", http.StatusMethodNotAllowed)
|
||||||
http.Error(w, "oops!!!", http.StatusMethodNotAllowed)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Http struct {
|
type Http struct {
|
||||||
|
Reference in New Issue
Block a user