(t *testing.T)
| 240 | } |
| 241 | |
| 242 | func TestPostAcceptsJSONOnly(t *testing.T) { |
| 243 | gin.SetMode(gin.TestMode) |
| 244 | srv := newTestServer(nil) |
| 245 | |
| 246 | r := gin.New() |
| 247 | r.POST("/mcp", func(c *gin.Context) { |
| 248 | common.GinAppendValues(c, conf.UserKey, &model.User{ID: 1, Role: model.ADMIN}) |
| 249 | srv.handlePost(c) |
| 250 | }) |
| 251 | |
| 252 | req := httptest.NewRequest(http.MethodPost, "http://example.com/mcp", strings.NewReader(`{ |
| 253 | "jsonrpc":"2.0", |
| 254 | "id":1, |
| 255 | "method":"initialize" |
| 256 | }`)) |
| 257 | req.Header.Set("Accept", "application/json") |
| 258 | req.Header.Set("Origin", "http://example.com") |
| 259 | |
| 260 | w := httptest.NewRecorder() |
| 261 | r.ServeHTTP(w, req) |
| 262 | |
| 263 | if w.Code != http.StatusOK { |
| 264 | t.Fatalf("unexpected status: got %d want %d", w.Code, http.StatusOK) |
| 265 | } |
| 266 | resp := decodeResponse(t, w) |
| 267 | if resp.Error != nil { |
| 268 | t.Fatalf("unexpected error response: %+v", resp.Error) |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | func TestPostAcceptsWildcardAccept(t *testing.T) { |
| 273 | gin.SetMode(gin.TestMode) |
nothing calls this directly
no test coverage detected