mirror of https://github.com/adamdruppe/arsd.git
html5 server side event helpers and data uri and reorganization
This commit is contained in:
parent
7d35054cb5
commit
3d15b86362
56
cgi.d
56
cgi.d
|
@ -21,25 +21,6 @@ import std.process;
|
||||||
|
|
||||||
import std.zlib;
|
import std.zlib;
|
||||||
|
|
||||||
T[] consume(T)(T[] range, int count) {
|
|
||||||
if(count > range.length)
|
|
||||||
count = range.length;
|
|
||||||
return range[count..$];
|
|
||||||
}
|
|
||||||
|
|
||||||
int locationOf(T)(T[] data, string item) {
|
|
||||||
const(ubyte[]) d = cast(const(ubyte[])) data;
|
|
||||||
const(ubyte[]) i = cast(const(ubyte[])) item;
|
|
||||||
|
|
||||||
for(int a = 0; a < d.length; a++) {
|
|
||||||
if(a + i.length > d.length)
|
|
||||||
return -1;
|
|
||||||
if(d[a..a+i.length] == i)
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/+
|
/+
|
||||||
/// If you pass -1 to Cgi.this() as maxContentLength, it
|
/// If you pass -1 to Cgi.this() as maxContentLength, it
|
||||||
|
@ -96,6 +77,27 @@ struct CgiVariableStream {
|
||||||
}
|
}
|
||||||
+/
|
+/
|
||||||
|
|
||||||
|
|
||||||
|
T[] consume(T)(T[] range, int count) {
|
||||||
|
if(count > range.length)
|
||||||
|
count = range.length;
|
||||||
|
return range[count..$];
|
||||||
|
}
|
||||||
|
|
||||||
|
int locationOf(T)(T[] data, string item) {
|
||||||
|
const(ubyte[]) d = cast(const(ubyte[])) data;
|
||||||
|
const(ubyte[]) i = cast(const(ubyte[])) item;
|
||||||
|
|
||||||
|
for(int a = 0; a < d.length; a++) {
|
||||||
|
if(a + i.length > d.length)
|
||||||
|
return -1;
|
||||||
|
if(d[a..a+i.length] == i)
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/// If you are doing a custom cgi class, mixing this in can take care of
|
/// If you are doing a custom cgi class, mixing this in can take care of
|
||||||
/// the required constructors for you
|
/// the required constructors for you
|
||||||
mixin template ForwardCgiConstructors() {
|
mixin template ForwardCgiConstructors() {
|
||||||
|
@ -174,6 +176,10 @@ static:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string makeDataUrl(string mimeType, in ubyte[] data) {
|
||||||
|
auto data64 = Base64.encode(data);
|
||||||
|
return "data:" ~ mimeType ~ ";base64," ~ assumeUnique(data64);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// The main interface with the web request
|
/// The main interface with the web request
|
||||||
|
@ -245,6 +251,9 @@ class Cgi {
|
||||||
if(ae.length && ae.indexOf("gzip") != -1)
|
if(ae.length && ae.indexOf("gzip") != -1)
|
||||||
acceptsGzip = true;
|
acceptsGzip = true;
|
||||||
|
|
||||||
|
accept = getenv("HTTP_ACCEPT");
|
||||||
|
lastEventId = getenv("HTTP_LAST_EVENT_ID");
|
||||||
|
|
||||||
auto ka = getenv("HTTP_CONNECTION");
|
auto ka = getenv("HTTP_CONNECTION");
|
||||||
if(ka.length && ka.toLower().indexOf("keep-alive") != -1)
|
if(ka.length && ka.toLower().indexOf("keep-alive") != -1)
|
||||||
keepAliveRequested = true;
|
keepAliveRequested = true;
|
||||||
|
@ -381,6 +390,12 @@ class Cgi {
|
||||||
string value = header[colon+2..$]; // skip the colon and the space
|
string value = header[colon+2..$]; // skip the colon and the space
|
||||||
|
|
||||||
switch(name) {
|
switch(name) {
|
||||||
|
case "accept":
|
||||||
|
accept = value;
|
||||||
|
break;
|
||||||
|
case "last-event-id":
|
||||||
|
lastEventId = value;
|
||||||
|
break;
|
||||||
case "authorization":
|
case "authorization":
|
||||||
authorization = value;
|
authorization = value;
|
||||||
break;
|
break;
|
||||||
|
@ -927,6 +942,8 @@ class Cgi {
|
||||||
immutable(char[]) pathInfo;
|
immutable(char[]) pathInfo;
|
||||||
immutable(char[]) scriptName;
|
immutable(char[]) scriptName;
|
||||||
immutable(char[]) authorization;
|
immutable(char[]) authorization;
|
||||||
|
immutable(char[]) accept;
|
||||||
|
immutable(char[]) lastEventId;
|
||||||
|
|
||||||
immutable(char[]) queryString;
|
immutable(char[]) queryString;
|
||||||
immutable(char[]) referrer;
|
immutable(char[]) referrer;
|
||||||
|
@ -1292,7 +1309,6 @@ string printDate(DateTime date) {
|
||||||
|
|
||||||
version(with_cgi_packed) {
|
version(with_cgi_packed) {
|
||||||
// This is temporary until Phobos supports base64
|
// This is temporary until Phobos supports base64
|
||||||
import std.base64;
|
|
||||||
immutable(ubyte)[] base64UrlDecode(string e) {
|
immutable(ubyte)[] base64UrlDecode(string e) {
|
||||||
string encoded = e.idup;
|
string encoded = e.idup;
|
||||||
while (encoded.length % 4) {
|
while (encoded.length % 4) {
|
||||||
|
|
Loading…
Reference in New Issue