Skip to content
This repository was archived by the owner on Jul 7, 2024. It is now read-only.

Commit df62024

Browse files
author
dl0im
committed
feat: add proxy info in script context
1 parent be9b1b5 commit df62024

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

engine/engine.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ func VMNew() *goja.Runtime {
3030
func VMNewWithVendor(p interfaces.Vendor, network interfaces.RequestOptionsNetwork) *goja.Runtime {
3131
vm := VMNew()
3232

33+
if p != nil {
34+
pi := p.ProxyInfo()
35+
vm.Set("proxy", vm.ToValue(pi.Map()))
36+
} else {
37+
vm.Set("proxy", nil)
38+
}
39+
3340
vm.Set("fetch", factory.FetchFactory(vm, p, network))
3441
vm.Set("netcat", factory.NetCatFactory(vm, p, network))
3542

interfaces/proxy.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ type ProxyInfo struct {
3737
Address string
3838
Type ProxyType
3939
}
40+
41+
func (pi *ProxyInfo) Map() map[string]string {
42+
return map[string]string{
43+
"Name": pi.Name,
44+
"Address": pi.Address,
45+
"Type": string(pi.Type),
46+
}
47+
}

0 commit comments

Comments
 (0)