Skip to content

Commit

Permalink
Bump std@0.88.0
Browse files Browse the repository at this point in the history
Fix utf8 stuff
  • Loading branch information
LarsVomMars committed Feb 26, 2021
1 parent e70eae5 commit 56e324a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
11 changes: 5 additions & 6 deletions context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
Cookie,
decode,
deleteCookie,
encode,
getCookies,
join,
MultipartReader,
Expand Down Expand Up @@ -77,9 +75,10 @@ export class Context {

private async readRequestBody(): Promise<Record<string, unknown>> {
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;
Expand All @@ -97,7 +96,7 @@ export class Context {
const query: Record<string, string> = {};
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;
Expand All @@ -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");
}

Expand All @@ -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",
Expand Down
14 changes: 6 additions & 8 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit 56e324a

Please sign in to comment.