コード例 #1
0
//printThreadHead renders head part of thread page with cookie.
func (t *threadCGI) printThreadHead(path, id string, page int, ca *thread.Cache, rss string) error {
	switch {
	case ca.HasRecord():
		if !t.IsBot() {
			download.GetCache(true, ca)
		} else {
			log.Println("bot detected, not get cache")
		}
	case t.CheckGetCache():
		ca.Subscribe()
		if t.Req.FormValue("search_new_file") == "" {
			download.GetCache(true, ca)
		}
	default:
		t.Print404(nil, id)
		return errors.New("no records")
	}
	var access string
	var newcookie []*http.Cookie
	if ca.HasRecord() && id == "" && page == 0 {
		cookie, err := t.Req.Cookie("access")
		if err == nil {
			access = cookie.Value
		} else {
			log.Println(err)
		}
		newcookie = t.setCookie(ca, access)
	}
	t.Header(path, rss, newcookie, false)
	return nil
}