mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-27 16:24:07 +02:00
send connection close
This commit is contained in:
parent
1b8ffa54a0
commit
903ee83a1e
@ -163,6 +163,9 @@ void http_ctx_res_headers_set(HttpCtx* ctx, const char* key, const char* value)
|
||||
|
||||
void http_ctx_respond(HttpCtx* ctx, int status, const char* body)
|
||||
{
|
||||
// https://httpwg.org/specs/rfc9112.html#persistent.tear-down
|
||||
http_ctx_res_headers_set(ctx, "Connection", "close");
|
||||
|
||||
String res;
|
||||
string_construct(&res);
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
import { assertEquals, assertMatch } from "jsr:@std/assert";
|
||||
|
||||
import axios from "npm:axios";
|
||||
|
||||
const url = `http://127.0.0.1:8080`;
|
||||
// const url = `http://10.135.51.114:8080`;
|
||||
|
||||
@ -10,40 +8,61 @@ const email = `mash.skp_${Math.floor(Math.random() * 100000)}@edu.mercantec.dk`;
|
||||
const password = "Merc1234";
|
||||
|
||||
Deno.test("test", async () => {
|
||||
const registerRes = await axios.post(
|
||||
`${url}/api/users/register`,
|
||||
const registerRes = await post<{ ok: boolean }>(
|
||||
`/api/users/register`,
|
||||
{ name, email, password },
|
||||
{ responseType: "json" },
|
||||
)
|
||||
.then((res) => res.data);
|
||||
);
|
||||
|
||||
assertEquals(registerRes, { ok: true });
|
||||
|
||||
const loginRes = await axios.post(
|
||||
`${url}/api/sessions/login`,
|
||||
const loginRes = await post<{
|
||||
ok: true;
|
||||
token: string;
|
||||
}>(
|
||||
"/api/sessions/login",
|
||||
{ email, password },
|
||||
{ responseType: "json" },
|
||||
).then((res) => res.data);
|
||||
);
|
||||
|
||||
assertEquals(loginRes.ok, true);
|
||||
assertMatch(loginRes.token, /^[0-9a-zA-Z]+$/);
|
||||
const token = loginRes.token;
|
||||
|
||||
const sessionUserRes = await axios.get(
|
||||
`${url}/api/sessions/user`,
|
||||
{ headers: { "Session-Token": token } },
|
||||
)
|
||||
.then((res) => res.data)
|
||||
.catch((error) => error.response.data);
|
||||
const sessionUserRes = await get<{
|
||||
ok: boolean;
|
||||
user: unknown;
|
||||
}>(
|
||||
"/api/sessions/user",
|
||||
{ "Session-Token": token },
|
||||
);
|
||||
|
||||
assertEquals(sessionUserRes.ok, true);
|
||||
console.log(sessionUserRes.user);
|
||||
|
||||
const logoutRes = await axios.post(
|
||||
`${url}/api/sessions/logout`,
|
||||
const logoutRes = await post<{ ok: boolean }>(
|
||||
"/api/sessions/logout",
|
||||
{},
|
||||
{ responseType: "json", headers: { "Session-Token": token } },
|
||||
).then((res) => res.data);
|
||||
{ "Session-Token": token },
|
||||
);
|
||||
|
||||
assertEquals(logoutRes, { ok: true });
|
||||
});
|
||||
|
||||
function get<Res>(
|
||||
path: string,
|
||||
headers: Record<string, string>,
|
||||
): Promise<Res> {
|
||||
return fetch(`${url}${path}`, { headers })
|
||||
.then((res) => res.json());
|
||||
}
|
||||
|
||||
function post<Res, Req = unknown>(
|
||||
path: string,
|
||||
body: Req,
|
||||
headers: Record<string, string> = {},
|
||||
): Promise<Res> {
|
||||
return fetch(`${url}${path}`, {
|
||||
method: "post",
|
||||
headers: { ...headers, "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
}).then((res) => res.json());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user