MCPcopy Index your code
hub / github.com/coder/coder / ServeHTTP

Method ServeHTTP

coderd/healthcheck/websocket.go:112–157  ·  view source on GitHub ↗
(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

110}
111
112func (s *WebsocketEchoServer) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
113 if s.Error != nil {
114 rw.WriteHeader(s.Code)
115 _, _ = rw.Write([]byte(s.Error.Error()))
116 return
117 }
118
119 ctx := r.Context()
120 c, err := websocket.Accept(rw, r, &websocket.AcceptOptions{})
121 if err != nil {
122 rw.WriteHeader(http.StatusBadRequest)
123 _, _ = rw.Write([]byte(fmt.Sprint("unable to accept:", err)))
124 return
125 }
126 defer c.Close(websocket.StatusGoingAway, "goodbye")
127
128 echo := func() error {
129 ctx, cancel := context.WithTimeout(ctx, time.Second*10)
130 defer cancel()
131
132 typ, r, err := c.Reader(ctx)
133 if err != nil {
134 return xerrors.Errorf("get reader: %w", err)
135 }
136
137 w, err := c.Writer(ctx, typ)
138 if err != nil {
139 return xerrors.Errorf("get writer: %w", err)
140 }
141
142 _, err = io.Copy(w, r)
143 if err != nil {
144 return xerrors.Errorf("echo message: %w", err)
145 }
146
147 err = w.Close()
148 return err
149 }
150
151 for {
152 err := echo()
153 if err != nil {
154 return
155 }
156 }
157}

Callers 15

ExtractTaskParamFunction · 0.45
ExtractGroupByNameParamFunction · 0.45
ExtractGroupParamFunction · 0.45
TestTrustedOriginsFunction · 0.45
TestCorruptedHeadersFunction · 0.45
TestAddressFamiliesFunction · 0.45
TestEffectiveHostFunction · 0.45
TestApplicationProxyFunction · 0.45
TestAPIKeyFunction · 0.45
CSPHeadersFunction · 0.45
ExtractOAuth2Function · 0.45

Calls 9

echoStruct · 0.85
WriteMethod · 0.65
ContextMethod · 0.65
CloseMethod · 0.65
CopyMethod · 0.65
WriteHeaderMethod · 0.45
ErrorMethod · 0.45
AcceptMethod · 0.45
ErrorfMethod · 0.45

Tested by 15

TestTrustedOriginsFunction · 0.36
TestCorruptedHeadersFunction · 0.36
TestAddressFamiliesFunction · 0.36
TestEffectiveHostFunction · 0.36
TestApplicationProxyFunction · 0.36
TestAPIKeyFunction · 0.36
TestTaskParamFunction · 0.36
TestOrganizationParamFunction · 0.36
TestOAuth2Function · 0.36
TestRateLimitFunction · 0.36