Aadi Gupta commited on
Commit
b77ac18
Β·
1 Parent(s): 145fe35

Remove broken HTTP middleware; notebook already uses correct {action:{...}} format

Browse files
Files changed (1) hide show
  1. server/app.py +0 -37
server/app.py CHANGED
@@ -8,13 +8,10 @@ baseline, actions) are mounted on the same FastAPI app.
8
 
9
  from __future__ import annotations
10
 
11
- import json
12
  import sys
13
  from pathlib import Path
14
  from typing import Any, Dict, List, Optional
15
 
16
- from fastapi import Request
17
- from fastapi.responses import JSONResponse
18
  from pydantic import Field
19
 
20
  # Ensure project root is importable
@@ -186,40 +183,6 @@ app = create_app(
186
  )
187
 
188
 
189
- # ── Compatibility middleware: accept flat {action_type, parameters} on /step ─
190
-
191
- @app.middleware("http")
192
- async def _normalize_step(request: Request, call_next):
193
- """Allow clients to POST flat {action_type, parameters} to /step.
194
-
195
- The OpenEnv framework requires {"action": {...}}. This middleware
196
- transparently wraps the flat format so existing clients keep working.
197
- """
198
- if request.method == "POST" and request.url.path in ("/step", "/step/"):
199
- raw = await request.body()
200
- if raw:
201
- try:
202
- data = json.loads(raw)
203
- if isinstance(data, dict) and "action_type" in data and "action" not in data:
204
- wrapped = json.dumps({"action": data}).encode()
205
- # Rebuild headers with corrected content-length
206
- new_headers = [
207
- (k, v) for k, v in request.scope["headers"]
208
- if k.lower() != b"content-length"
209
- ]
210
- new_headers.append((b"content-length", str(len(wrapped)).encode()))
211
- scope = dict(request.scope)
212
- scope["headers"] = new_headers
213
-
214
- async def _receive():
215
- return {"type": "http.request", "body": wrapped, "more_body": False}
216
-
217
- request = Request(scope, _receive)
218
- except Exception:
219
- pass
220
- return await call_next(request)
221
-
222
-
223
  # ── Custom endpoints (tasks, grader, baseline, actions) ──────────────────
224
 
225
  from pydantic import BaseModel
 
8
 
9
  from __future__ import annotations
10
 
 
11
  import sys
12
  from pathlib import Path
13
  from typing import Any, Dict, List, Optional
14
 
 
 
15
  from pydantic import Field
16
 
17
  # Ensure project root is importable
 
183
  )
184
 
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  # ── Custom endpoints (tasks, grader, baseline, actions) ──────────────────
187
 
188
  from pydantic import BaseModel