Skip to content

Commit 923075e

Browse files
committed
Fix headers
1 parent c962a22 commit 923075e

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

template/server/envs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ async def get_envs(access_token: Optional[str]) -> dict:
1111
if LOCAL:
1212
return {"E2B_TEST_VARIABLE": "true"}
1313
async with httpx.AsyncClient() as client:
14+
headers = {}
1415
if access_token:
15-
client.headers["X-Access-Token"] = f"{access_token}"
16-
response = await client.get(f"http://localhost:{ENVD_PORT}/envs")
16+
headers["X-Access-Token"] = f"{access_token}"
17+
response = await client.get(
18+
f"http://localhost:{ENVD_PORT}/envs", headers=headers
19+
)
1720
return response.json()

template/server/main.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import logging
22
import sys
3-
import uuid
43
import httpx
54

65
from typing import Dict, Union, Literal, Set
76

87
from contextlib import asynccontextmanager
9-
from fastapi import FastAPI
8+
from fastapi import FastAPI, Request
109
from fastapi.responses import PlainTextResponse
1110

1211
from api.models.context import Context
@@ -70,18 +69,18 @@ async def get_health():
7069

7170

7271
@app.post("/execute")
73-
async def post_execute(request: ExecutionRequest):
74-
logger.info(f"Executing code: {request.code}")
72+
async def post_execute(request: Request, exec_request: ExecutionRequest):
73+
logger.info(f"Executing code: {exec_request.code}")
7574

76-
if request.context_id and request.language:
75+
if exec_request.context_id and exec_request.language:
7776
return PlainTextResponse(
7877
"Only one of context_id or language can be provided",
7978
status_code=400,
8079
)
8180

8281
context_id = None
83-
if request.language:
84-
language = normalize_language(request.language)
82+
if exec_request.language:
83+
language = normalize_language(exec_request.language)
8584

8685
async with await default_websockets.get_lock(language):
8786
context_id = default_websockets.get(language)
@@ -97,8 +96,8 @@ async def post_execute(request: ExecutionRequest):
9796
context_id = context.id
9897
default_websockets[language] = context_id
9998

100-
elif request.context_id:
101-
context_id = request.context_id
99+
elif exec_request.context_id:
100+
context_id = exec_request.context_id
102101

103102
if context_id:
104103
ws = websockets.get(context_id, None)
@@ -107,14 +106,14 @@ async def post_execute(request: ExecutionRequest):
107106

108107
if not ws:
109108
return PlainTextResponse(
110-
f"Context {request.context_id} not found",
109+
f"Context {exec_request.context_id} not found",
111110
status_code=404,
112111
)
113112

114113
return StreamingListJsonResponse(
115114
ws.execute(
116-
request.code,
117-
env_vars=request.env_vars,
115+
exec_request.code,
116+
env_vars=exec_request.env_vars,
118117
access_token=request.headers.get("X-Access-Token", None),
119118
)
120119
)

0 commit comments

Comments
 (0)