MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / isWriteRequest

Function isWriteRequest

src/ui-server/security.ts:85–104  ·  view source on GitHub ↗
(
  pathname: string,
  headers: { marker: string | undefined; contentType: string | undefined }
)

Source from the content-addressed store, hash-verified

83 * @param headers `x-codegraph-ui` and, for a body-carrying method, `content-type`
84 */
85export function isWriteRequest(
86 pathname: string,
87 headers: { marker: string | undefined; contentType: string | undefined }
88): { ok: true } | { ok: false; reason: string } {
89 // Writes live under /api/ and nowhere else. The static side of this server
90 // serves a built bundle; there is nothing there to POST to.
91 if (pathname !== '/api' && !pathname.startsWith('/api/')) {
92 return { ok: false, reason: 'Only the /api/ endpoints accept writes.' };
93 }
94 if (headers.marker === undefined || headers.marker.trim() === '') {
95 return { ok: false, reason: `A write must carry the ${WRITE_HEADER} header.` };
96 }
97 if (headers.contentType !== undefined) {
98 const type = headers.contentType.split(';')[0]?.trim().toLowerCase();
99 if (type !== '' && type !== WRITE_CONTENT_TYPE) {
100 return { ok: false, reason: `A write body must be ${WRITE_CONTENT_TYPE}.` };
101 }
102 }
103 return { ok: true };
104}
105
106interface HostParts {
107 hostname: string;

Callers 1

handleRequestFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected