diff --git a/context.ts b/context.ts index 2cb3dcb..e5c02ed 100644 --- a/context.ts +++ b/context.ts @@ -1,8 +1,6 @@ import { Cookie, - decode, deleteCookie, - encode, getCookies, join, MultipartReader, @@ -77,9 +75,10 @@ export class Context { private async readRequestBody(): Promise> { const contentType = this.#request.headers.get("Content-Type"); + const decoder = new TextDecoder(); if (contentType?.includes("application/json")) { - return JSON.parse(decode(await Deno.readAll(this.#request.body))); + return JSON.parse(decoder.decode(await Deno.readAll(this.#request.body))); } else if (contentType?.includes("multipart/form-data")) { const match = contentType.match(/boundary=([^\s]+)/); const boundary = match ? match[1] : undefined; @@ -97,7 +96,7 @@ export class Context { const query: Record = {}; for ( const [key, value] of new URLSearchParams( - decode(await Deno.readAll(this.#request.body)), + decoder.decode(await Deno.readAll(this.#request.body)), ) ) { query[key] = value; @@ -124,7 +123,7 @@ export class Context { text(text: string, code = Status.OK) { this.#response.status = code; - this.#response.body = encode(text); + this.#response.body = new TextEncoder().encode(text); this.#response.headers?.append("Content-Type", "text/plain;charset=UTF-8"); } @@ -133,7 +132,7 @@ export class Context { if (typeof obj === "object") { obj = JSON.stringify(obj); } - this.#response.body = encode(obj as string); + this.#response.body = new TextEncoder().encode(obj as string); this.#response.headers?.append( "Content-Type", "application/json;charset=UTF-8", diff --git a/deps.ts b/deps.ts index 16e1d2a..362ad53 100644 --- a/deps.ts +++ b/deps.ts @@ -6,20 +6,18 @@ export { ServerRequest, setCookie, Status, -} from "https://deno.land/std@0.87.0/http/mod.ts"; +} from "https://deno.land/std@0.88.0/http/mod.ts"; export type { Cookie, HTTPOptions, Response, -} from "https://deno.land/std@0.87.0/http/mod.ts"; +} from "https://deno.land/std@0.88.0/http/mod.ts"; -export { decode, encode } from "https://deno.land/std@0.87.0/encoding/utf8.ts"; +export { MultipartReader } from "https://deno.land/std@0.88.0/mime/mod.ts"; -export { MultipartReader } from "https://deno.land/std@0.87.0/mime/mod.ts"; +export * as log from "https://deno.land/std@0.88.0/log/mod.ts"; -export * as log from "https://deno.land/std@0.87.0/log/mod.ts"; +export { format } from "https://deno.land/std@0.88.0/datetime/mod.ts"; -export { format } from "https://deno.land/std@0.87.0/datetime/mod.ts"; - -export { extname, join } from "https://deno.land/std@0.87.0/path/mod.ts"; +export { extname, join } from "https://deno.land/std@0.88.0/path/mod.ts";