from mitmproxy import http

def request(flow: http.HTTPFlow):
    host = 'api.cursor.com' if flow.request.path.startswith('/v1/') else 'api2.cursor.sh'
    flow.request.host = host
    flow.request.port = 443
    flow.request.scheme = 'https'
    flow.request.headers['Host'] = host

def response(flow: http.HTTPFlow):
    print('TRANSPORT', flow.request.method, flow.request.path.split('?')[0], flow.request.http_version, 'status', flow.response.status_code, flush=True)

def responseheaders(flow: http.HTTPFlow):
    flow.response.stream = True
    print('HEADERS', flow.request.path.split('?')[0], flow.response.status_code, flow.response.headers.get('content-type', ''), flush=True)
