MCPcopy
hub / github.com/usememos/memos / GetHTMLMeta

Function GetHTMLMeta

internal/httpgetter/html_meta.go:136–158  ·  view source on GitHub ↗
(urlStr string)

Source from the content-addressed store, hash-verified

134}
135
136func GetHTMLMeta(urlStr string) (*HTMLMeta, error) {
137 if err := validateURL(urlStr); err != nil {
138 return nil, err
139 }
140
141 response, err := httpClient.Get(urlStr)
142 if err != nil {
143 return nil, err
144 }
145 defer response.Body.Close()
146
147 mediatype, err := getMediatype(response)
148 if err != nil {
149 return nil, err
150 }
151 if mediatype != "text/html" {
152 return nil, errors.New("not a HTML page")
153 }
154
155 htmlMeta := extractHTMLMeta(io.LimitReader(response.Body, maxHTMLMetaBytes))
156 enrichSiteMeta(response.Request.URL, htmlMeta)
157 return htmlMeta, nil
158}
159
160func extractHTMLMeta(resp io.Reader) *HTMLMeta {
161 tokenizer := html.NewTokenizer(resp)

Callers 4

TestGetHTMLMetaFunction · 0.85

Calls 6

validateURLFunction · 0.85
getMediatypeFunction · 0.85
extractHTMLMetaFunction · 0.85
enrichSiteMetaFunction · 0.85
GetMethod · 0.65
CloseMethod · 0.65

Tested by 4

TestGetHTMLMetaFunction · 0.68