INNER CODE UNIT · TypeScript

gateDirectoryWrite

phase-rs/phase · lobby-worker/src/index.ts:89

async function gateDirectoryWrite(
  request: Request,
  maxBytes: number,
  keyPrefix: string,
  limiter?: RateLimit,
): Promise<Response | null> {
  const contentLength = request.headers.get("content-length");
  const ip = request.headers.get("CF-Connecting-IP") ?? "";
  const gate = await checkIngestGate({
    contentLength: contentLength === null ? null : Number(contentLength),
    maxBytes,
    // The purpose prefix keeps the two counters disjoint even if the two
    // namespace ids were ever collapsed.
    key: `${keyPrefix}:${ip}`,
    limiter: limiter as IngestLimiter | undefined,
  });
  if (gate.kind === "accept") return null;
  const status = gate.reason === "too_large" ? 413 : 429;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…