Skip to content

Commit 763f0f5

Browse files
committed
Implement blank stat endpoints
This is to reduce noisy log warnings that say the endpoints are 404s. We just do not support stats yet.
1 parent 366c021 commit 763f0f5

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

api/api.go

+11
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ func New(options *Options) *API {
128128
httpapi.WriteBytes(rw, http.StatusOK, []byte("Extension pages are not supported"))
129129
})
130130

131+
// Web extensions post stats to this endpoint.
132+
r.Post("/api/itemName/{publisher}.{name}/version/{version}/statType/{type}/vscodewebextension", func(rw http.ResponseWriter, r *http.Request) {
133+
httpapi.WriteBytes(rw, http.StatusOK, []byte("Extension stats are not supported"))
134+
})
135+
136+
// Non-web extensions post stats to this endpoint.
137+
r.Post("/api/publishers/{publisher}/extensions/{name}/{version}/stats", func(rw http.ResponseWriter, r *http.Request) {
138+
// Will have a `statType` query param.
139+
httpapi.WriteBytes(rw, http.StatusOK, []byte("Extension stats are not supported"))
140+
})
141+
131142
return api
132143
}
133144

api/api_test.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"net/http"
99
"net/http/httptest"
10+
"strings"
1011
"testing"
1112

1213
"github.com/stretchr/testify/require"
@@ -217,6 +218,16 @@ func TestAPI(t *testing.T) {
217218
Path: "/item",
218219
Status: http.StatusOK,
219220
},
221+
{
222+
Name: "WebExtensionStat",
223+
Path: "/api/itemName/vscodevim.vim/version/1.23.1/statType/1/vscodewebextension",
224+
Status: http.StatusOK,
225+
},
226+
{
227+
Name: "ExtensionStat",
228+
Path: "/api/publishers/vscodevim/extensions/vim/1.23.1/stats?statType=1",
229+
Status: http.StatusOK,
230+
},
220231
}
221232

222233
for _, c := range cases {
@@ -245,7 +256,7 @@ func TestAPI(t *testing.T) {
245256

246257
var resp *http.Response
247258
var err error
248-
if c.Path == "/api/extensionquery" {
259+
if strings.HasPrefix(c.Path, "/api") {
249260
var body []byte
250261
if str, ok := c.Request.(string); ok {
251262
body = []byte(str)

0 commit comments

Comments
 (0)