MCPcopy Create free account
hub / github.com/bywwcnll/StreamPanel / processXHRChunk

Function processXHRChunk

inject.js:701–728  ·  view source on GitHub ↗
(contentType, chunk)

Source from the content-addressed store, hash-verified

699 }
700
701 function processXHRChunk(contentType, chunk) {
702 if (!chunk) return;
703
704 parseBuffer += chunk;
705 log('XHR received chunk, length:', chunk.length);
706
707 if (contentType.includes('text/event-stream')) {
708 const boundaryIndex = findCompleteSSEBoundary(parseBuffer);
709 if (boundaryIndex === null) return;
710
711 const completeData = parseBuffer.substring(0, boundaryIndex);
712 parseBuffer = parseBuffer.substring(boundaryIndex);
713
714 const events = parseSSEEvents(completeData);
715 for (const event of events) {
716 emitXHRMessage(event.event, event.data, event.id);
717 }
718 } else if (contentType.includes('application/x-ndjson') || contentType.includes('application/jsonlines')) {
719 const lines = parseBuffer.split(/\r?\n/);
720 parseBuffer = lines.pop() || '';
721
722 for (const line of lines) {
723 if (line.trim()) {
724 emitXHRMessage('message', line);
725 }
726 }
727 }
728 }
729
730 function flushXHRBuffer(contentType) {
731 if (!parseBuffer.trim()) {

Callers 1

inject.jsFile · 0.85

Calls 4

findCompleteSSEBoundaryFunction · 0.85
parseSSEEventsFunction · 0.85
emitXHRMessageFunction · 0.85
logFunction · 0.70

Tested by

no test coverage detected