MCPcopy Create free account
hub / github.com/1buran/rHttp / Update

Method Update

main.go:838–1110  ·  view source on GitHub ↗
(msg tea.Msg)

Source from the content-addressed store, hash-verified

836var usedScreenLines int
837
838func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
839 var cmds []tea.Cmd = make([]tea.Cmd, len(m.inputs))
840
841 switch msg := msg.(type) {
842 case FileInputReader:
843 if msg.Error != nil {
844 sbar.Error(msg.Error.Error())
845 return m, nil
846 }
847 switch msg.Id {
848 case sessionLoad:
849 sbar.Info("load session from: " + msg.Path)
850 m.focused = 0
851 m.focusPrompt(0)
852 return loadSession(m, msg.Reader)
853 case payload:
854 sbar.Info("add payload, read data from: " + msg.Path)
855 m.focused = 0
856 m.focusPrompt(0)
857 return loadPayload(m, msg.Reader, msg.Path)
858 }
859 case FileInputWriter:
860 if msg.Error != nil {
861 sbar.Error(msg.Error.Error())
862 return m, nil
863 }
864 ses, _ := NewSession(
865 m.req, m.res, sbar.GetReqCount(),
866 sbar.GetResTime(), formValues, m.resBodyLines)
867 err := ses.Save(msg.Writer)
868 if err != nil {
869 sbar.Error(err.Error())
870 }
871 sbar.Info("saved session to: " + msg.Path)
872 m.focused = 0
873 m.focusPrompt(0)
874 return m, nil
875 case CheckboxUpdated: // todo: move this to checkboxHandler (Checkbox.Update loop)
876 switch msg.Id {
877 case https:
878 m.setHttps(msg.On)
879 }
880 case Timer:
881 sbar.SetResTime(msg.elapsedTime())
882 cmd := func() tea.Msg {
883 return msg.payload
884 }
885 return m, cmd
886
887 case *http.Response:
888 defer msg.Body.Close()
889 buf, _ := io.ReadAll(msg.Body)
890 m.res = msg
891 m.resBodyLines = formatRespBody(
892 m.res.Header.Get("content-type"), string(buf),
893 m.checkboxes[checkboxIndex(autoformat)].IsOn())
894 sbar.SetResStatusCode(m.res.StatusCode)
895 sbar.SetResProto(m.res.ProtoMajor, m.res.Proto, m.req.URL.Scheme)

Callers 1

checkboxHandlerMethod · 0.45

Calls 15

focusPromptMethod · 0.95
SaveMethod · 0.95
setHttpsMethod · 0.95
clearRespArtefactsMethod · 0.95
prevInputMethod · 0.95
nextInputMethod · 0.95
blurAllPromptsMethod · 0.95
delReqHeaderMethod · 0.95
delReqParamMethod · 0.95
delReqCookieMethod · 0.95
delReqFormMethod · 0.95
checkboxHandlerMethod · 0.95

Tested by

no test coverage detected