// attempt to push any push urls (if found and if the HTTP client supports HTTP/2)
attempt to push any push urls (if found and if the HTTP client supports HTTP/2)
// attempt to push any push urls ( if found and if the HTTP client supports HTTP / 2 )
func push(pusher http.Pusher, w http.ResponseWriter, req *http.Request, item *CacheItem) {
	if item.ishtml {
		if item.parsed == false {
			links, body, err := findPushLinks(bytes.NewReader(item.buffer))
			if err == nil {
				for _, link := range links {
					item.AddURL(link)
				}
				item.buffer = []byte(body)
				item.gzipbuf = gzipbuf(item.buffer)
			}
			item.parsed = true
		}
		if item.pushurls != nil && len(item.pushurls) > 0 {
			for _, pushurl := range item.pushurls {
				headers := http.Header{}
				ext := filepath.Ext(pushurl)
				headers.Set("Content-Type", mime.TypeByExtension(ext))
				headers.Set("Cache-Control", fmt.Sprintf("public, max-age=%d, must-revalidate", cacheMaxAge))
				opts := &http.PushOptions{
					Method: "GET",
					Header: headers,
				}
				if err := pusher.Push(pushurl, opts); err != nil {
					log.Errorf("error pushing %s. %v", pushurl, err)
				}
			}
		}
	}
	stream(w, req, item)
}
func push ( pusher http . Pusher , w http . ResponseWriter , req * http . Request , item * CacheItem ) { if item . ishtml { if item . parsed == false { links , body , err := findPushLinks ( bytes . NewReader ( item . buffer ) ) if err == nil { for _ , link := range links { item . AddURL ( link ) } item . buffer = [ ] byte ( body ) item . gzipbuf = gzipbuf ( item . buffer ) } item . parsed = true } if item . pushurls != nil && len ( item . pushurls ) > 0 { for _ , pushurl := range item . pushurls { headers := http . Header { } ext := filepath . Ext ( pushurl ) headers . Set ( " " , mime . TypeByExtension ( ext ) ) headers . Set ( " " , fmt . Sprintf ( " " , cacheMaxAge ) ) opts := & http . PushOptions { Method : " " , Header : headers , } if err := pusher . Push ( pushurl , opts ) ; err != nil { log . Errorf ( " " , pushurl , err ) } } } } stream ( w , req , item ) }
attempt to push any push urls (if found and if the HTTP client supports HTTP/2)
attempt to push any push urls ( if found and if the HTTP client supports HTTP / 2 )
// check to see if the content target is an HTML doc // if not yet parsed, we will parse the HTML // attempt to extract push links from the parsed AST // add each url found from the doc // since we remove the links, we need to set the updated body // if we have push urls, go ahead and push them // stream the regular content back to the client