multipasta
Advanced tools
Comparing version 0.1.19 to 0.1.20
@@ -26,3 +26,3 @@ "use strict"; | ||
key: "", | ||
value: "", | ||
value: undefined, | ||
crlf: 0, | ||
@@ -37,3 +37,3 @@ previousChunk: undefined, | ||
state.key = ""; | ||
state.value = ""; | ||
state.value = undefined; | ||
state.crlf = 0; | ||
@@ -45,2 +45,8 @@ state.previousChunk = undefined; | ||
} | ||
function concatUint8Array(a, b) { | ||
const newUint8Array = new Uint8Array(a.length + b.length); | ||
newUint8Array.set(a); | ||
newUint8Array.set(b, a.length); | ||
return newUint8Array; | ||
} | ||
function error(reason) { | ||
@@ -74,4 +80,4 @@ return reset({ | ||
if (chunk[i] === 58) { | ||
state.key += decoder.decode(chunk.slice(start, i)).toLowerCase(); | ||
if (state.key === "") { | ||
state.key += decoder.decode(chunk.subarray(start, i)).toLowerCase(); | ||
if (state.key.length === 0) { | ||
return error("InvalidHeaderName"); | ||
@@ -96,3 +102,3 @@ } | ||
if (i === end) { | ||
state.key += decoder.decode(chunk.slice(start, end)).toLowerCase(); | ||
state.key += decoder.decode(chunk.subarray(start, end)).toLowerCase(); | ||
return constContinue; | ||
@@ -154,4 +160,5 @@ } | ||
} else if (state.crlf >= 2) { | ||
state.value += decoder.decode(chunk.slice(start, i - state.crlf)); | ||
state.headers[state.key] = state.value; | ||
state.value = state.value === undefined ? chunk.subarray(start, i - state.crlf) : concatUint8Array(state.value, chunk.subarray(start, i - state.crlf)); | ||
const value = decoder.decode(state.value); | ||
state.headers[state.key] = value; | ||
start = i; | ||
@@ -172,3 +179,3 @@ state.size--; | ||
state.key = ""; | ||
state.value = ""; | ||
state.value = undefined; | ||
state.crlf = 0; | ||
@@ -183,3 +190,3 @@ state.state = State.key; | ||
if (i === end) { | ||
state.value += decoder.decode(chunk.slice(start, end)); | ||
state.value = state.value === undefined ? chunk.subarray(start, end) : concatUint8Array(state.value, chunk.subarray(start, end)); | ||
return constContinue; | ||
@@ -186,0 +193,0 @@ } |
@@ -20,3 +20,3 @@ const constMaxPairs = 100; | ||
key: "", | ||
value: "", | ||
value: undefined, | ||
crlf: 0, | ||
@@ -31,3 +31,3 @@ previousChunk: undefined, | ||
state.key = ""; | ||
state.value = ""; | ||
state.value = undefined; | ||
state.crlf = 0; | ||
@@ -39,2 +39,8 @@ state.previousChunk = undefined; | ||
} | ||
function concatUint8Array(a, b) { | ||
const newUint8Array = new Uint8Array(a.length + b.length); | ||
newUint8Array.set(a); | ||
newUint8Array.set(b, a.length); | ||
return newUint8Array; | ||
} | ||
function error(reason) { | ||
@@ -68,4 +74,4 @@ return reset({ | ||
if (chunk[i] === 58) { | ||
state.key += decoder.decode(chunk.slice(start, i)).toLowerCase(); | ||
if (state.key === "") { | ||
state.key += decoder.decode(chunk.subarray(start, i)).toLowerCase(); | ||
if (state.key.length === 0) { | ||
return error("InvalidHeaderName"); | ||
@@ -90,3 +96,3 @@ } | ||
if (i === end) { | ||
state.key += decoder.decode(chunk.slice(start, end)).toLowerCase(); | ||
state.key += decoder.decode(chunk.subarray(start, end)).toLowerCase(); | ||
return constContinue; | ||
@@ -148,4 +154,5 @@ } | ||
} else if (state.crlf >= 2) { | ||
state.value += decoder.decode(chunk.slice(start, i - state.crlf)); | ||
state.headers[state.key] = state.value; | ||
state.value = state.value === undefined ? chunk.subarray(start, i - state.crlf) : concatUint8Array(state.value, chunk.subarray(start, i - state.crlf)); | ||
const value = decoder.decode(state.value); | ||
state.headers[state.key] = value; | ||
start = i; | ||
@@ -166,3 +173,3 @@ state.size--; | ||
state.key = ""; | ||
state.value = ""; | ||
state.value = undefined; | ||
state.crlf = 0; | ||
@@ -177,3 +184,3 @@ state.state = State.key; | ||
if (i === end) { | ||
state.value += decoder.decode(chunk.slice(start, end)); | ||
state.value = state.value === undefined ? chunk.subarray(start, end) : concatUint8Array(state.value, chunk.subarray(start, end)); | ||
return constContinue; | ||
@@ -180,0 +187,0 @@ } |
{ | ||
"name": "multipasta", | ||
"version": "0.1.19", | ||
"version": "0.1.20", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -41,3 +41,3 @@ import { Continue, FailureReason, ReturnValue } from "../HeadersParser.js" | ||
key: "", | ||
value: "", | ||
value: undefined as undefined | Uint8Array, | ||
crlf: 0, | ||
@@ -53,3 +53,3 @@ previousChunk: undefined as undefined | Uint8Array, | ||
state.key = "" | ||
state.value = "" | ||
state.value = undefined | ||
state.crlf = 0 | ||
@@ -62,2 +62,9 @@ state.previousChunk = undefined | ||
function concatUint8Array(a: Uint8Array, b: Uint8Array): Uint8Array { | ||
const newUint8Array = new Uint8Array(a.length + b.length) | ||
newUint8Array.set(a) | ||
newUint8Array.set(b, a.length) | ||
return newUint8Array | ||
} | ||
function error(reason: FailureReason) { | ||
@@ -91,4 +98,4 @@ return reset({ _tag: "Failure", reason, headers: state.headers }) | ||
if (chunk[i] === 58) { | ||
state.key += decoder.decode(chunk.slice(start, i)).toLowerCase() | ||
if (state.key === "") { | ||
state.key += decoder.decode(chunk.subarray(start, i)).toLowerCase() | ||
if (state.key.length === 0) { | ||
return error("InvalidHeaderName") | ||
@@ -119,3 +126,3 @@ } | ||
if (i === end) { | ||
state.key += decoder.decode(chunk.slice(start, end)).toLowerCase() | ||
state.key += decoder.decode(chunk.subarray(start, end)).toLowerCase() | ||
return constContinue | ||
@@ -183,4 +190,11 @@ } | ||
} else if (state.crlf >= 2) { | ||
state.value += decoder.decode(chunk.slice(start, i - state.crlf)) | ||
state.headers[state.key] = state.value | ||
state.value = | ||
state.value === undefined | ||
? chunk.subarray(start, i - state.crlf) | ||
: concatUint8Array( | ||
state.value, | ||
chunk.subarray(start, i - state.crlf), | ||
) | ||
const value = decoder.decode(state.value) | ||
state.headers[state.key] = value | ||
@@ -204,3 +218,3 @@ start = i | ||
state.key = "" | ||
state.value = "" | ||
state.value = undefined | ||
state.crlf = 0 | ||
@@ -217,3 +231,6 @@ state.state = State.key | ||
if (i === end) { | ||
state.value += decoder.decode(chunk.slice(start, end)) | ||
state.value = | ||
state.value === undefined | ||
? chunk.subarray(start, end) | ||
: concatUint8Array(state.value, chunk.subarray(start, end)) | ||
return constContinue | ||
@@ -220,0 +237,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
189121
3128