| 177 | } |
| 178 | |
| 179 | func (c *Command) start(ctx context.Context) error { |
| 180 | addr := fmt.Sprintf(":%d", c.from) |
| 181 | lis, err := net.Listen("tcp", addr) |
| 182 | if err != nil { |
| 183 | return fmt.Errorf("listen: %w", err) |
| 184 | } |
| 185 | |
| 186 | p := martian.NewProxy() |
| 187 | p.SetRequestModifier(c) |
| 188 | p.SetRoundTripper(c) |
| 189 | p.SetDial(func(network string, addr string) (net.Conn, error) { |
| 190 | return new(net.Dialer).DialContext(ctx, network, addr) |
| 191 | }) |
| 192 | |
| 193 | slog.Debug("listening for new connections", "addr", addr) |
| 194 | if err := p.Serve(lis); err != nil { |
| 195 | return fmt.Errorf("serve: %w", err) |
| 196 | } |
| 197 | return nil |
| 198 | } |
| 199 | |
| 200 | func (c *Command) ModifyRequest(req *http.Request) error { |
| 201 | if c.global.Devtools.HijackPath != "" && req.URL.Path == c.global.Devtools.HijackPath { |