func TestAppend(t *testing.T) { err := errors.Appends(ErrFoo, "inner string") if err.Error() != "Fooey. inner string" { t.Error("String error for ReverseWraps") return } err = errors.Appendf(ErrFoo, "%s", Strger) if err.Error() != "Fooey. stringer out" { t.Error("String error for ReverseWrapf") return } }
// The default header checker will only proceed if it's 200 OK and an HTML Content-Type func defaultCheckHeader(crawler *Crawler, url string, status int, header http.Header) error { if status != 200 { return errors.Appends(ErrBadHttpCode, "Received "+strconv.Itoa(status)+" "+http.StatusText(status)) } contentType := header.Get("Content-Type") if contentType == "" { return errors.Appends(ErrBadContentType, "Content-Type header missing") } mediaType, _, err := mime.ParseMediaType(contentType) if err != nil { return errors.Appends(ErrBadContentType, "Malformated Content-Type header") } if mediaType == "text/html" || mediaType == "application/xhtml+xml" { return nil } else { return errors.Appends(ErrBadContentType, mediaType+" is not supported") } }