func (h *FilteringHandler) OnRequest(r *http.Request, ctx *goproxy.ProxyCtx) ( *http.Request, *http.Response) { host := r.URL.Host if host == "" { host = r.Host } rq := &adblock.Request{ URL: r.URL.String(), Domain: host, OriginDomain: getReferrerDomain(r), } rules := h.Cache.Rules() start := time.Now() matched, id := rules.Matcher.Match(rq) end := time.Now() duration := end.Sub(start) / time.Millisecond if matched { rule := rules.Rules[id] log.Printf("rejected in %dms: %s\n", duration, r.URL.String()) log.Printf(" by %s\n", rule) return r, goproxy.NewResponse(r, goproxy.ContentTypeText, http.StatusNotFound, "Not Found") } ctx.UserData = &ProxyState{ Duration: duration, URL: r.URL.String(), } return r, nil }