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

Method workspaceProxyCoordinate

enterprise/coderd/workspaceproxycoordinate.go:22–70  ·  view source on GitHub ↗

@Summary Workspace Proxy Coordinate @ID workspace-proxy-coordinate @Security CoderSessionToken @Tags Enterprise @Success 101 @Router /api/v2/workspaceproxies/me/coordinate [get] @x-apidocgen {"skip": true}

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

20// @Router /api/v2/workspaceproxies/me/coordinate [get]
21// @x-apidocgen {"skip": true}
22func (api *API) workspaceProxyCoordinate(rw http.ResponseWriter, r *http.Request) {
23 ctx := r.Context()
24
25 version := "1.0"
26 msgType := websocket.MessageText
27 qv := r.URL.Query().Get("version")
28 if qv != "" {
29 version = qv
30 }
31 if err := proto.CurrentVersion.Validate(version); err != nil {
32 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
33 Message: "Unknown or unsupported API version",
34 Validations: []codersdk.ValidationError{
35 {Field: "version", Detail: err.Error()},
36 },
37 })
38 return
39 }
40 maj, _, _ := apiversion.Parse(version)
41 if maj >= 2 {
42 // Versions 2+ use dRPC over a binary connection
43 msgType = websocket.MessageBinary
44 }
45
46 api.AGPL.WebsocketWaitMutex.Lock()
47 api.AGPL.WebsocketWaitGroup.Add(1)
48 api.AGPL.WebsocketWaitMutex.Unlock()
49 defer api.AGPL.WebsocketWaitGroup.Done()
50
51 conn, err := websocket.Accept(rw, r, nil)
52 if err != nil {
53 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
54 Message: "Failed to accept websocket.",
55 Detail: err.Error(),
56 })
57 return
58 }
59
60 ctx, nc := codersdk.WebsocketNetConn(ctx, conn, msgType)
61 defer nc.Close()
62
63 id := uuid.New()
64 err = api.tailnetService.ServeMultiAgentClient(ctx, version, nc, id)
65 if err != nil {
66 _ = conn.Close(websocket.StatusInternalError, err.Error())
67 } else {
68 _ = conn.Close(websocket.StatusGoingAway, "")
69 }
70}

Callers

nothing calls this directly

Calls 15

WriteFunction · 0.92
ParseFunction · 0.92
WebsocketNetConnFunction · 0.92
ServeMultiAgentClientMethod · 0.80
ContextMethod · 0.65
GetMethod · 0.65
ValidateMethod · 0.65
AddMethod · 0.65
CloseMethod · 0.65
NewMethod · 0.65
ErrorMethod · 0.45
LockMethod · 0.45

Tested by

no test coverage detected