feat: Add Support for Proxy with Interceptor (#77)

This commit is contained in:
Abhisek Datta
2025-12-10 08:34:28 +05:30
committed by GitHub
parent a8723cd680
commit 21eb05373f
15 changed files with 1852 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
package main
import (
"fmt"
"time"
"github.com/safedep/pmg/proxy"
)
type loggingInterceptor struct {
domains []string
}
func newLoggingInterceptor() *loggingInterceptor {
return &loggingInterceptor{
domains: []string{
"registry.npmjs.org",
"registry.yarnpkg.com",
"pypi.org",
"files.pythonhosted.org",
},
}
}
func (li *loggingInterceptor) Name() string {
return "logging-interceptor"
}
func (li *loggingInterceptor) ShouldIntercept(ctx *proxy.RequestContext) bool {
for _, domain := range li.domains {
if ctx.Hostname == domain {
return true
}
}
return false
}
func (li *loggingInterceptor) HandleRequest(ctx *proxy.RequestContext) (*proxy.InterceptorResponse, error) {
fmt.Printf("LOGGING INTERCEPTOR: [%s] %s %s %s\n",
ctx.StartTime.Format(time.RFC3339),
ctx.RequestID,
ctx.Method,
ctx.URL.String(),
)
return &proxy.InterceptorResponse{
Action: proxy.ActionAllow,
}, nil
}