// walk through the HTML content and see if we can find any
// <link rel="push" href="...">
// elements and if so, pull them out so that we can HTTP/2 push
// them to clients that support it
walk through the HTML content and see if we can find any

elements and if so, pull them out so that we can HTTP/2 push
them to clients that support it
// walk through the HTML content and see if we can find any // <link rel = " push " href = " ... " > // elements and if so pull them out so that we can HTTP / 2 push // them to clients that support it
func findPushLinks(reader io.Reader) ([]string, string, error) {
	doc, err := html.Parse(reader)
	if err != nil {
		return nil, "", err
	}
	urls := make([]string, 0)
	nodes := make([]*html.Node, 0)
	var visitor func(*html.Node)
	visitor = func(node *html.Node) {
		if node.Type == html.ElementNode && node.Data == "link" {
			var relFound, noPush bool
			var href string
			for _, a := range node.Attr {
				if a.Key == "rel" {
					if a.Val == "push" || a.Val == "preload" {
						relFound = true
					} else {
						break
					}
				} else if a.Key == "href" {
					href = a.Val
				} else if a.Key == "nopush" {
					noPush = true
				}
			}
			if relFound && noPush == false && href != "" {
				urls = append(urls, href)
				nodes = append(nodes, node)
			}
		}
		for c := node.FirstChild; c != nil; c = c.NextSibling {
			visitor(c)
		}
	}
	visitor(doc)
	for _, node := range nodes {
		node.Parent.RemoveChild(node)
	}
	var content bytes.Buffer
	html.Render(&content, doc)
	return urls, content.String(), nil
}
func findPushLinks ( reader io . Reader ) ( [ ] string , string , error ) { doc , err := html . Parse ( reader ) if err != nil { return nil , " " , err } urls := make ( [ ] string , 0 ) nodes := make ( [ ] * html . Node , 0 ) var visitor func ( * html . Node ) visitor = func ( node * html . Node ) { if node . Type == html . ElementNode && node . Data == " " { var relFound , noPush bool var href string for _ , a := range node . Attr { if a . Key == " " { if a . Val == " " || a . Val == " " { relFound = true } else { break } } else if a . Key == " " { href = a . Val } else if a . Key == " " { noPush = true } } if relFound && noPush == false && href != " " { urls = append ( urls , href ) nodes = append ( nodes , node ) } } for c := node . FirstChild ; c != nil ; c = c . NextSibling { visitor ( c ) } } visitor ( doc ) for _ , node := range nodes { node . Parent . RemoveChild ( node ) } var content bytes . Buffer html . Render ( & content , doc ) return urls , content . String ( ) , nil }
walk through the HTML content and see if we can find any
walk through the HTML content and see if we can find any
// remove it since it's only for server side use