Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(core): Handle both variations of multipart/mixed preamble (#3172)

authored by

Phil Pluckthun and committed by
GitHub
a4d1aa15 932eee3f

+17 -9
+5
.changeset/itchy-queens-scream.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Handle `multipart/mixed` variations starting with boundary rather than CRLF and a boundary.
+12 -9
packages/core/src/internal/fetchSource.ts
··· 77 77 response: Response 78 78 ): AsyncIterableIterator<ExecutionResult> { 79 79 const boundaryHeader = contentType.match(boundaryHeaderRe); 80 - const boundary = '\r\n--' + (boundaryHeader ? boundaryHeader[1] : '-'); 80 + const boundary = '--' + (boundaryHeader ? boundaryHeader[1] : '-'); 81 81 let isPreamble = true; 82 82 let payload: any; 83 - for await (const chunk of split(streamBody(response), boundary)) { 83 + for await (let chunk of split(streamBody(response), '\r\n' + boundary)) { 84 84 if (isPreamble) { 85 85 isPreamble = false; 86 - } else { 87 - try { 88 - yield (payload = JSON.parse( 89 - chunk.slice(chunk.indexOf('\r\n\r\n') + 4) 90 - )); 91 - } catch (error) { 92 - if (!payload) throw error; 86 + const preambleIndex = chunk.indexOf(boundary); 87 + if (preambleIndex > -1) { 88 + chunk = chunk.slice(preambleIndex + boundary.length); 89 + } else { 90 + continue; 93 91 } 92 + } 93 + try { 94 + yield (payload = JSON.parse(chunk.slice(chunk.indexOf('\r\n\r\n') + 4))); 95 + } catch (error) { 96 + if (!payload) throw error; 94 97 } 95 98 if (payload && !payload.hasNext) break; 96 99 }