summaryrefslogtreecommitdiff
path: root/textproto.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-11-08 12:58:43 -0500
committerRyan Dahl <ry@tinyclouds.org>2018-11-08 12:58:43 -0500
commitfb0b99408b1ce0c8061d654e9dae3fd8221efa6f (patch)
tree82a3edc234b67ea9f9c8e8f75176a9700dc7504e /textproto.ts
parent0c324a442ef4a296bd925972dfbe3fc94c60b256 (diff)
Add tests for TextProtoReader.readMIMEHeader()
Original: https://github.com/denoland/deno_std/commit/36edda18ab75ea8287088478d46e89e5e8d6be0f
Diffstat (limited to 'textproto.ts')
-rw-r--r--textproto.ts25
1 files changed, 14 insertions, 11 deletions
diff --git a/textproto.ts b/textproto.ts
index b4336c90d..61ca45a8a 100644
--- a/textproto.ts
+++ b/textproto.ts
@@ -5,6 +5,7 @@
import { BufReader, BufState } from "./bufio.ts";
import { charCode } from "./util.ts";
+import { Headers } from "./headers.ts";
const asciiDecoder = new TextDecoder("ascii");
function str(buf: Uint8Array): string {
@@ -53,37 +54,38 @@ export class TextProtoReader {
* "Long-Key": {"Even Longer Value"},
* }
*/
- /*
- async readMIMEHeader(): Promise<Headers> {
+ async readMIMEHeader(): Promise<[Headers, BufState]> {
let m = new Headers();
let line: Uint8Array;
// The first line cannot start with a leading space.
let [buf, err] = await this.r.peek(1);
- if (buf[0] == charCode(' ') || buf[0] == charCode('\t')) {
+ if (buf[0] == charCode(" ") || buf[0] == charCode("\t")) {
[line, err] = await this.readLineSlice();
}
[buf, err] = await this.r.peek(1);
- if (err == null && (buf[0] == charCode(' ') || buf[0] == charCode('\t'))) {
- throw new ProtocolError(`malformed MIME header initial line: ${str(line)}`)
+ if (err == null && (buf[0] == charCode(" ") || buf[0] == charCode("\t"))) {
+ throw new ProtocolError(
+ `malformed MIME header initial line: ${str(line)}`
+ );
}
while (true) {
let [kv, err] = await this.readLineSlice(); // readContinuedLineSlice
if (kv.byteLength == 0) {
- return m;
+ return [m, err];
}
// Key ends at first colon; should not have trailing spaces
// but they appear in the wild, violating specs, so we remove
// them if present.
- let i = kv.indexOf(charCode(':'));
+ let i = kv.indexOf(charCode(":"));
if (i < 0) {
throw new ProtocolError(`malformed MIME header line: ${str(kv)}`);
}
let endKey = i;
- while (endKey > 0 && kv[endKey - 1] == charCode(' ')) {
+ while (endKey > 0 && kv[endKey - 1] == charCode(" ")) {
endKey--;
}
@@ -99,8 +101,10 @@ export class TextProtoReader {
// Skip initial spaces in value.
i++; // skip colon
- while (i < kv.byteLength &&
- (kv[i] == charCode(' ') || kv[i] == charCode('\t'))) {
+ while (
+ i < kv.byteLength &&
+ (kv[i] == charCode(" ") || kv[i] == charCode("\t"))
+ ) {
i++;
}
let value = str(kv.subarray(i));
@@ -112,7 +116,6 @@ export class TextProtoReader {
}
}
}
- */
async readLineSlice(): Promise<[Uint8Array, BufState]> {
// this.closeDot();