Parcourir la Source

Read one byte of /favicon.ico before using it

That's probably not enough, but at least fixes sites that simply return
an empty response.
Lucas Stadler 9 ans auparavant
Parent
commit
8849d4e3e4
1 fichiers modifiés avec 5 ajouts et 0 suppressions
  1. 5 0
      go/favicon/favicon.go

+ 5 - 0
go/favicon/favicon.go

@ -132,6 +132,11 @@ func GetCanonicalFavicon(u string) (string, error) {
132 132
	if resp.StatusCode >= 400 || resp.Header.Get("Content-Length") == "0" {
133 133
		return "", errors.New("no /favicon.ico")
134 134
	}
135
	buf := make([]byte, 0, 1)
136
	n, err := resp.Body.Read(buf)
137
	if err != nil || n == 0 {
138
		return "", errors.New("can't read /favicon.ico")
139
	}
135 140
	fmt.Println("favicon.ico", resp.Request.URL.String(), faviconUrl)
136 141
	return resp.Request.URL.String(), nil
137 142
}