mitm: Refactor & Add url

This commit is contained in:
世界
2025-02-04 15:00:59 +08:00
parent fb3007fa80
commit 003423745e
42 changed files with 3152 additions and 1164 deletions

View File

@@ -3,12 +3,20 @@ package adapter
import (
"context"
"net/http"
"sync"
"time"
)
type ScriptManager interface {
Lifecycle
Scripts() []Script
// Script(name string) (Script, bool)
Script(name string) (Script, bool)
SurgeCache() *SurgeInMemoryCache
}
type SurgeInMemoryCache struct {
sync.RWMutex
Data map[string]string
}
type Script interface {
@@ -19,21 +27,11 @@ type Script interface {
Close() error
}
type GenericScript interface {
type SurgeScript interface {
Script
Run(ctx context.Context) error
}
type HTTPScript interface {
Script
Match(requestURL string) bool
RequiresBody() bool
MaxSize() int64
}
type HTTPRequestScript interface {
HTTPScript
Run(ctx context.Context, request *http.Request, body []byte) (*HTTPRequestScriptResult, error)
ExecuteGeneric(ctx context.Context, scriptType string, timeout time.Duration, arguments []string) error
ExecuteHTTPRequest(ctx context.Context, timeout time.Duration, request *http.Request, body []byte, binaryBody bool, arguments []string) (*HTTPRequestScriptResult, error)
ExecuteHTTPResponse(ctx context.Context, timeout time.Duration, request *http.Request, response *http.Response, body []byte, binaryBody bool, arguments []string) (*HTTPResponseScriptResult, error)
}
type HTTPRequestScriptResult struct {
@@ -49,11 +47,6 @@ type HTTPRequestScriptResponse struct {
Body []byte
}
type HTTPResponseScript interface {
HTTPScript
Run(ctx context.Context, request *http.Request, response *http.Response, body []byte) (*HTTPResponseScriptResult, error)
}
type HTTPResponseScriptResult struct {
Status int
Headers http.Header