コード例 #1
0
ファイル: proxy.go プロジェクト: cinderalla/proxyblock
func notifyProxyEvent(action string, req *http.Request, events chan longpolling.Event) {
	// in the event localhost isn't added to noproxy, don't emit localhost event
	normUrl := strings.ToLower(req.URL.String())
	if strings.HasPrefix(normUrl, "http://127.0.0.1:") ||
		strings.HasPrefix(normUrl, "http://127.0.0.1/") ||
		strings.HasPrefix(normUrl, "127.0.0.1:") ||
		strings.HasPrefix(normUrl, "127.0.0.1/") {
		// no events for you!
		return
	}
	var category string
	if referer := req.Header.Get("Referer"); len(referer) > 0 {
		category = utils.StripProxyExceptionStringFromUrl(referer)
	} else {
		category = utils.StripProxyExceptionStringFromUrl(req.URL.String())
	}
	event := longpolling.Event{utils.TimeToEpochMilliseconds(time.Now()), category, action + ": " + req.URL.String()}
	events <- event
}
コード例 #2
0
ファイル: longpolling.go プロジェクト: cinderalla/proxyblock
func (eb *EventBuffer) GetEventsSince(since time.Time) ([]Event, error) {
	events := make([]Event, 0) // NOTE: having init cap > 0 has zero value Event
	// structs which we don't want!
	// events are bufferd FIFO with the most recent event in the front of the
	// buffer (list)
	for element := eb.List.Front(); element != nil; element = element.Next() {
		event, ok := element.Value.(*Event)
		if !ok {
			return nil, fmt.Errorf("Found non-event type in event buffer.")
		}
		// event time is after since time arg? convert since to epoch ms
		if event.Timestamp > utils.TimeToEpochMilliseconds(since) {
			events = append(events, Event{event.Timestamp, event.Category, event.Data})
		} else {
			// we've made it to events we've seen before, stop searching
			break
		}
	}
	// NOTE: events has the most recent event first followed by any older events
	// that occurred since client's last seen event
	// TODO: consider reversing order?  or is it an advantage to have
	// newest first so handled with more priority?  TODO: make this an option?
	return events, nil
}