summaryrefslogtreecommitdiff
path: root/std/http/io.ts
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2020-04-27 20:08:20 +0200
committerGitHub <noreply@github.com>2020-04-27 14:08:20 -0400
commitc190a0dbc48e7de6a63a2f633f59054d40800600 (patch)
tree0516b0539903fc39e8f9c823c0a7194a0843622a /std/http/io.ts
parentd440495b6bc20eb8008397f3c744d8fa1ab578f5 (diff)
Improve std/http/io.ts parseHTTPVersion (#4930)
Diffstat (limited to 'std/http/io.ts')
-rw-r--r--std/http/io.ts21
1 files changed, 5 insertions, 16 deletions
diff --git a/std/http/io.ts b/std/http/io.ts
index 2c2fea48a..d87a03306 100644
--- a/std/http/io.ts
+++ b/std/http/io.ts
@@ -287,7 +287,7 @@ export async function writeResponse(
/**
* ParseHTTPVersion parses a HTTP version string.
- * "HTTP/1.0" returns (1, 0, true).
+ * "HTTP/1.0" returns (1, 0).
* Ported from https://github.com/golang/go/blob/f5c43b9/src/net/http/request.go#L766-L792
*/
export function parseHTTPVersion(vers: string): [number, number] {
@@ -300,7 +300,6 @@ export function parseHTTPVersion(vers: string): [number, number] {
default: {
const Big = 1000000; // arbitrary upper bound
- const digitReg = /^\d+$/; // test if string is only digit
if (!vers.startsWith("HTTP/")) {
break;
@@ -312,24 +311,14 @@ export function parseHTTPVersion(vers: string): [number, number] {
}
const majorStr = vers.substring(vers.indexOf("/") + 1, dot);
- const major = parseInt(majorStr);
- if (
- !digitReg.test(majorStr) ||
- isNaN(major) ||
- major < 0 ||
- major > Big
- ) {
+ const major = Number(majorStr);
+ if (!Number.isInteger(major) || major < 0 || major > Big) {
break;
}
const minorStr = vers.substring(dot + 1);
- const minor = parseInt(minorStr);
- if (
- !digitReg.test(minorStr) ||
- isNaN(minor) ||
- minor < 0 ||
- minor > Big
- ) {
+ const minor = Number(minorStr);
+ if (!Number.isInteger(minor) || minor < 0 || minor > Big) {
break;
}