alexbrazier / react-native-network-logger

An HTTP network request monitor for React Native with in-app interface for iOS and Android with no native code
MIT License
550 stars 50 forks source link

Changed `ignoredHosts` to `ignoredPatterns` #68

Closed trajano closed 1 year ago

trajano commented 1 year ago

Feature Request I want to filter out the /ping calls from the server done by NetInfo but they're in the same host as my main server that I am trying to monitor.

If we say the request has the following text

HEAD https://trajano.net/ping

It would simplify us by having rules that look like

ignoredPatterns: [
  /^HEAD https:\/\/trajano.net\/ping$/
]

Additional context

alexbrazier commented 1 year ago

Hi @trajano, this is probably something that can be added and I think someone previously made a start to it. Do you need it to filter by the request method as well, e.g. HEAD as this might be a more complicated pattern to match?

trajano commented 1 year ago

I just made it so it's more flexible and ideally simpler for you to code because you're just filtering on the request line which you already have. But no I don't think I would need the method filter at the moment.

trajano commented 1 year ago
    if (this.ignoredHosts) {
      const host = extractHost(url);
      if (host && this.ignoredHosts.has(host)) {
        return;
      }
    }

I just found that block. I guess this would change to something like

    if (this.ignoredPatterns) {
      const toMatch = `${method} ${url}`
      if (this.ignoredPatterns.find((p) => p.matches(toMatch))) {
        return;
     }
    }
alexbrazier commented 1 year ago

I've just added a PR which should cover this. Let me know what you think of it.

Another option I was thinking was to pass a callback function which gives you control of what to ignore.