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

Method HandleReadFile

agent/agentfiles/files.go:62–86  ·  view source on GitHub ↗
(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

60}
61
62func (api *API) HandleReadFile(rw http.ResponseWriter, r *http.Request) {
63 ctx := r.Context()
64
65 query := r.URL.Query()
66 parser := httpapi.NewQueryParamParser().RequiredNotEmpty("path")
67 path := parser.String(query, "", "path")
68 offset := parser.PositiveInt64(query, 0, "offset")
69 limit := parser.PositiveInt64(query, 0, "limit")
70 parser.ErrorExcessParams(query)
71 if len(parser.Errors) > 0 {
72 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
73 Message: "Query parameters have invalid values.",
74 Validations: parser.Errors,
75 })
76 return
77 }
78
79 status, err := api.streamFile(ctx, rw, path, offset, limit)
80 if err != nil {
81 httpapi.Write(ctx, rw, status, codersdk.Response{
82 Message: err.Error(),
83 })
84 return
85 }
86}
87
88func (api *API) streamFile(ctx context.Context, rw http.ResponseWriter, path string, offset, limit int64) (HTTPResponseCode, error) {
89 logger := api.logger.With(agentchat.Fields(ctx)...)

Callers

nothing calls this directly

Calls 9

streamFileMethod · 0.95
NewQueryParamParserFunction · 0.92
WriteFunction · 0.92
RequiredNotEmptyMethod · 0.80
PositiveInt64Method · 0.80
ErrorExcessParamsMethod · 0.80
ContextMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected