-
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.
- Loading branch information
Showing
15 changed files
with
263 additions
and
37 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
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
34 changes: 34 additions & 0 deletions
34
...ain/java/io/github/danthe1st/httpsintercept/handler/http/HttpResponseContentAccessor.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,34 @@ | ||
package io.github.danthe1st.httpsintercept.handler.http; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.handler.codec.http.FullHttpResponse; | ||
import org.bouncycastle.util.Arrays; | ||
|
||
public class HttpResponseContentAccessor { | ||
private ByteBuf contentBuf; | ||
private byte[] bytes; | ||
|
||
public HttpResponseContentAccessor(FullHttpResponse res) { | ||
contentBuf = res.content(); | ||
} | ||
|
||
public byte[] getBytes() { | ||
ensureBytesPresent(); | ||
return Arrays.copyOf(bytes, bytes.length); | ||
} | ||
|
||
public String getAsString() { | ||
ensureBytesPresent(); | ||
return new String(bytes, StandardCharsets.UTF_8); | ||
} | ||
|
||
private void ensureBytesPresent() { | ||
if(bytes == null){ | ||
ByteBuf buf = contentBuf.copy(); | ||
bytes = new byte[buf.readableBytes()]; | ||
buf.readBytes(bytes); | ||
} | ||
} | ||
} |
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
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
16 changes: 16 additions & 0 deletions
16
src/main/java/io/github/danthe1st/httpsintercept/rules/PostForwardRule.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,16 @@ | ||
package io.github.danthe1st.httpsintercept.rules; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes.Type; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import io.github.danthe1st.httpsintercept.handler.http.HttpResponseContentAccessor; | ||
import io.github.danthe1st.httpsintercept.rules.post.HtmlBasedBlocker; | ||
import io.netty.channel.Channel; | ||
import io.netty.handler.codec.http.FullHttpRequest; | ||
import io.netty.handler.codec.http.FullHttpResponse; | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") | ||
@JsonSubTypes({ @Type(name = "htmlBasedBlock", value = HtmlBasedBlocker.class) }) | ||
public interface PostForwardRule extends ProcessingRule { | ||
boolean processRequest(FullHttpRequest fullHttpRequest, FullHttpResponse response, HttpResponseContentAccessor responseContentAccessor, Channel channel); | ||
} |
Oops, something went wrong.