mirror of
https://git.macaw.me/skunky/uselesshttp.d.git
synced 2025-04-28 03:55:09 +03:00
Переход на edge-triggered; устранение жора CPU
This commit is contained in:
parent
ca1662c403
commit
06f9e483c3
2 changed files with 51 additions and 33 deletions
|
@ -30,27 +30,10 @@ string getStatus(short status) {
|
|||
return "WTF";
|
||||
}
|
||||
|
||||
// FIXME: memory leak
|
||||
void append(char[]* src, char symb) @nogc {
|
||||
import core.memory: pureMalloc, pureFree;
|
||||
auto arr =
|
||||
cast (char[])
|
||||
pureMalloc(src.length + 1)
|
||||
[0..src.length + 1];
|
||||
|
||||
arr[$-1..$] = symb;
|
||||
arr[0..$-1] = *src;
|
||||
*src = arr;
|
||||
|
||||
arr = null;
|
||||
pureFree(arr.ptr);
|
||||
}
|
||||
|
||||
void parseAndValidateURL(char[] url, Request* rqst) {
|
||||
if (url.length > 2048) throw new Exception("Too long URL");
|
||||
short parseAndValidateURL(char[] url, Request* rqst) {
|
||||
if (url.length > 2048) return 1; // too long url
|
||||
rqst.path = null;
|
||||
bool notArgumentPart;
|
||||
scope (exit) append(&rqst.args, '&');
|
||||
for (short i; i < url.length; ++i) {
|
||||
switch (url[i]) {
|
||||
case '?':
|
||||
|
@ -58,22 +41,24 @@ void parseAndValidateURL(char[] url, Request* rqst) {
|
|||
notArgumentPart = true;
|
||||
break;
|
||||
case '/':
|
||||
if (url.length > i+1 && url[i+1] != '/') append(&rqst.path, '/');
|
||||
if (url.length > i+1 && url[i+1] != '/') rqst.path ~= '/';
|
||||
break;
|
||||
case '=', '&':
|
||||
if (notArgumentPart && url[i-1] != url[i]) append(&rqst.args, url[i]);
|
||||
if (notArgumentPart && url[i-1] != url[i]) rqst.args ~= url[i];
|
||||
break;
|
||||
|
||||
case 'A': .. case 'Z':
|
||||
case 'a': .. case 'z':
|
||||
case '0': .. case '9':
|
||||
case '-', '_', '.', '~', '!', '$', '\'', '(', ')', '*', '+', ',', ';', '@', '[', ']', '|', '%':
|
||||
if (notArgumentPart) append(&rqst.args, url[i]);
|
||||
else append(&rqst.path, url[i]);
|
||||
if (notArgumentPart) rqst.args ~= url[i];
|
||||
else rqst.path ~= url[i];
|
||||
break;
|
||||
default: throw new Exception("Malformed URL");
|
||||
default: return 1; // malformed url
|
||||
}
|
||||
}
|
||||
rqst.args ~= '&';
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct Request {
|
||||
|
@ -173,5 +158,9 @@ private static enum Statuses: short { // спизженно с https://github.co
|
|||
@("Service Unavailable") service_unavailable = 503,
|
||||
@("Gateway Timeout") gateway_timeout = 504,
|
||||
@("HTTP Version Not Supported") http_version_not_supported = 505,
|
||||
@("Variant Also Negotiates") variant_also_negotiates = 506
|
||||
@("Variant Also Negotiates") variant_also_negotiates = 506,
|
||||
@("Insufficient Storage") insufficient_storage = 507, // (WebDAV)
|
||||
@("Loop Detected") loop_detected = 508, // (WebDAV)
|
||||
@("Not Extended") not_extended = 510,
|
||||
@("Network Authentication Required") network_authentication_required = 511
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue