44 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-01-03 14:51:07 +01:00
/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Auth-Server-Helper which is released under MIT.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, January 2021
*/
2020-12-30 17:21:56 +01:00
import http from 'http';
2021-01-01 14:14:19 +01:00
export class Response extends http.IncomingMessage {
2020-12-30 17:21:56 +01:00
body?: string;
}
2021-01-01 14:14:19 +01:00
export function get (
2021-01-03 14:51:07 +01:00
// eslint-disable-next-line default-param-last
headers: http.OutgoingHttpHeaders = {},
body?: string
2020-12-30 17:21:56 +01:00
): Promise<Response> {
return new Promise ((resolve) => {
2021-01-03 14:51:07 +01:00
const req = http.request ('http://localhost:3000', {
headers,
method: typeof body === 'string' ? 'POST' : 'GET'
}, (res: Response) => {
let data = '';
2020-12-30 17:21:56 +01:00
res.on ('data', (d) => {
2021-01-03 14:51:07 +01:00
data += d;
2020-12-30 17:21:56 +01:00
});
res.on ('end', () => {
2021-01-03 14:51:07 +01:00
res.body = data;
2020-12-30 17:21:56 +01:00
resolve (res);
});
});
2021-01-03 14:51:07 +01:00
if (typeof body === 'string')
req.write (body);
req.end ();
2020-12-30 17:21:56 +01:00
});
}
2021-01-01 14:14:19 +01:00
export function modify_signature (signature: string): string {
const dec = signature.split ('.');
dec[1] = '';
return dec.join ('.');
}