(w http.ResponseWriter, r *http.Request, tokenData TokenData)
| 533 | } |
| 534 | |
| 535 | func (h *WebUiHandler) handleCreateTunnel(w http.ResponseWriter, r *http.Request, tokenData TokenData) { |
| 536 | |
| 537 | pendingId, err := genRandomCode(16) |
| 538 | if err != nil { |
| 539 | w.WriteHeader(400) |
| 540 | h.alertDialog(w, r, err.Error(), "/tunnels") |
| 541 | } |
| 542 | |
| 543 | doneSignal := make(chan ReqResult) |
| 544 | h.mutex.Lock() |
| 545 | h.pendingRequests[pendingId] = doneSignal |
| 546 | h.mutex.Unlock() |
| 547 | |
| 548 | go func() { |
| 549 | |
| 550 | r.ParseForm() |
| 551 | |
| 552 | _, err := h.api.CreateTunnel(tokenData, r.Form) |
| 553 | |
| 554 | doneSignal <- ReqResult{err, "/tunnels"} |
| 555 | }() |
| 556 | |
| 557 | timeout := make(chan bool, 1) |
| 558 | go func() { |
| 559 | time.Sleep(100 * time.Millisecond) |
| 560 | timeout <- true |
| 561 | }() |
| 562 | |
| 563 | select { |
| 564 | case <-timeout: |
| 565 | url := fmt.Sprintf("/loading?id=%s", pendingId) |
| 566 | |
| 567 | data := &LoadingData{ |
| 568 | Head: h.headHtml, |
| 569 | TargetUrl: url, |
| 570 | } |
| 571 | |
| 572 | h.tmpl.ExecuteTemplate(w, "loading.tmpl", data) |
| 573 | if err != nil { |
| 574 | w.WriteHeader(500) |
| 575 | h.alertDialog(w, r, err.Error(), "/tunnels") |
| 576 | return |
| 577 | } |
| 578 | |
| 579 | case result := <-doneSignal: |
| 580 | if result.err != nil { |
| 581 | w.WriteHeader(400) |
| 582 | h.alertDialog(w, r, result.err.Error(), result.redirectUrl) |
| 583 | return |
| 584 | } |
| 585 | |
| 586 | http.Redirect(w, r, result.redirectUrl, 303) |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | func (h *WebUiHandler) sendLoginPage(w http.ResponseWriter, r *http.Request, code int) { |
| 591 |
no test coverage detected