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

Function loadSession

main.go:763–817  ·  view source on GitHub ↗

Load session: create and populate request and response from the given file.

(m model, r io.ReadCloser)

Source from the content-addressed store, hash-verified

761
762// Load session: create and populate request and response from the given file.
763func loadSession(m model, r io.ReadCloser) (tea.Model, tea.Cmd) {
764 ses, _ := NewSession(
765 m.req, m.res, sbar.GetReqCount(),
766 sbar.GetResTime(), formValues, m.resBodyLines)
767 err := ses.Load(r)
768 if err != nil {
769 sbar.Error(err.Error())
770 return m, nil
771 }
772 // Update state (request and response and some other stuff)
773 // TODO update suggestions and all this to separate function
774 sbar.SetReqCount(ses.ReqCount)
775 formValues = ses.Request.FormValues
776
777 // Create a new request instance
778 m.req = newReqest()
779
780 // req scheme (http or https)
781 m.req.URL.Scheme = ses.Request.Scheme
782 idx := checkboxIndex(https)
783 if m.req.URL.Scheme == "https" {
784 m.checkboxes[idx].SetOn()
785 } else {
786 m.checkboxes[idx].SetOff()
787 }
788
789 // req method
790 m.req.Method = ses.Request.Method
791 m.inputs[method].SetValue(ses.Request.Method)
792
793 // req host
794 m.req.Host = ses.Request.Host
795 m.req.URL.Host = ses.Request.Host
796 m.inputs[host].SetValue(ses.Request.Host)
797
798 // req url path
799 m.req.URL.Path = ses.Request.UrlPath
800 m.inputs[urlPath].SetValue(ses.Request.UrlPath)
801
802 // req headers
803 m.req.Header = ses.Request.Headers
804
805 // req query params
806 m.req.URL.RawQuery = ses.Request.RawQuery
807
808 // Create a new response instance
809 m.res = &http.Response{Request: m.req}
810 m.res.Status = ses.Response.Status
811 m.res.Proto = ses.Response.Proto
812 m.res.Header = ses.Response.Headers
813 m.resBodyLines = ses.Response.BodyLines
814 m.reqPayload = nothing
815
816 return m, nil
817}
818
819var filePayload string
820

Callers 1

UpdateMethod · 0.85

Calls 10

LoadMethod · 0.95
NewSessionFunction · 0.85
newReqestFunction · 0.85
checkboxIndexFunction · 0.85
GetReqCountMethod · 0.80
GetResTimeMethod · 0.80
ErrorMethod · 0.80
SetReqCountMethod · 0.80
SetOnMethod · 0.80
SetOffMethod · 0.80

Tested by

no test coverage detected