| 434 | } |
| 435 | |
| 436 | func (p *HTTPProxy) Stop() error { |
| 437 | if p.Script != nil { |
| 438 | if p.Script.Plugin.HasFunc("onExit") { |
| 439 | if _, err := p.Script.Call("onExit"); err != nil { |
| 440 | log.Error("Error while executing onExit callback: %s", "\nTraceback:\n "+err.(*otto.Error).String()) |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | if p.doRedirect && p.Redirection != nil { |
| 446 | p.Debug("disabling redirection %s", p.Redirection.String()) |
| 447 | if err := p.Sess.Firewall.EnableRedirection(p.Redirection, false); err != nil { |
| 448 | return err |
| 449 | } |
| 450 | p.Redirection = nil |
| 451 | } |
| 452 | |
| 453 | p.Sess.UnkCmdCallback = nil |
| 454 | |
| 455 | if p.isTLS { |
| 456 | p.isRunning = false |
| 457 | p.sniListener.Close() |
| 458 | return nil |
| 459 | } else { |
| 460 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 461 | defer cancel() |
| 462 | return p.Server.Shutdown(ctx) |
| 463 | } |
| 464 | } |