-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
forwarding rules, lazy host matching
- Loading branch information
Showing
19 changed files
with
411 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ | |
<version>5.10.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
<build> | ||
<plugins> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/io/github/danthe1st/httpsintercept/config/HostMatcherConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.github.danthe1st.httpsintercept.config; | ||
|
||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
public record HostMatcherConfig(Set<String> exactHosts, | ||
Set<String> hostParts, | ||
Set<String> hostRegexes) { | ||
public HostMatcherConfig { | ||
Objects.requireNonNull(exactHosts); | ||
Objects.requireNonNull(hostParts); | ||
Objects.requireNonNull(hostRegexes); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/io/github/danthe1st/httpsintercept/matcher/FilterIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.github.danthe1st.httpsintercept.matcher; | ||
|
||
import java.util.Iterator; | ||
import java.util.NoSuchElementException; | ||
import java.util.function.Predicate; | ||
|
||
final class FilterIterator<T> implements Iterator<T> { | ||
private final Iterator<T> iterator; | ||
private final Predicate<T> filter; | ||
private T current; | ||
|
||
public FilterIterator(Iterator<T> iterator, Predicate<T> filter) { | ||
this.iterator = iterator; | ||
this.filter = filter; | ||
} | ||
@Override | ||
public boolean hasNext() { | ||
if(current != null){ | ||
return true; | ||
} | ||
while(iterator.hasNext()){ | ||
T next = iterator.next(); | ||
if(filter.test(next)){ | ||
current = next; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public T next() { | ||
if(!hasNext()){ | ||
throw new NoSuchElementException(); | ||
} | ||
T ret = current; | ||
current = null; | ||
return ret; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/io/github/danthe1st/httpsintercept/matcher/HostPartIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.github.danthe1st.httpsintercept.matcher; | ||
|
||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
final class HostPartIterator<T> extends IteratingIterator<T> { | ||
private final String hostname; | ||
private int index = 0; | ||
private Iterator<T> current = Collections.emptyIterator(); | ||
private final Map<String, List<T>> hostParts; | ||
|
||
HostPartIterator(String hostname, Map<String, List<T>> hostParts) { | ||
this.hostname = hostname; | ||
this.hostParts = hostParts; | ||
} | ||
|
||
@Override | ||
protected Iterator<T> findNextIterator() { | ||
if(current.hasNext()){ | ||
return current; | ||
} | ||
do{ | ||
String hostPart = hostname.substring(index); | ||
if(hostParts.containsKey(hostPart)){ | ||
current = hostParts.get(hostPart).iterator(); | ||
if(current.hasNext()){ | ||
return current; | ||
} | ||
} | ||
}while((index = hostname.indexOf('.', index) + 1) != 0 && index < hostname.length()); | ||
return Collections.emptyIterator(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/io/github/danthe1st/httpsintercept/matcher/IteratingIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.github.danthe1st.httpsintercept.matcher; | ||
|
||
import java.util.Iterator; | ||
|
||
abstract class IteratingIterator<T> implements Iterator<T> { | ||
|
||
protected abstract Iterator<T> findNextIterator(); | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return findNextIterator().hasNext(); | ||
} | ||
|
||
@Override | ||
public T next() { | ||
return findNextIterator().next(); | ||
} | ||
} |
Oops, something went wrong.