mirror of https://github.com/adamdruppe/arsd.git
Merge branch 'master' of github.com:adamdruppe/arsd
This commit is contained in:
commit
19f897c6c4
65
http2.d
65
http2.d
|
@ -318,8 +318,25 @@ import std.conv;
|
||||||
import std.range;
|
import std.range;
|
||||||
|
|
||||||
|
|
||||||
|
private AddressFamily family(string unixSocketPath) {
|
||||||
|
if(unixSocketPath.length)
|
||||||
|
return AddressFamily.UNIX;
|
||||||
|
else // FIXME: what about ipv6?
|
||||||
|
return AddressFamily.INET;
|
||||||
|
}
|
||||||
|
|
||||||
// Copy pasta from cgi.d, then stripped down
|
version(Windows)
|
||||||
|
private class UnixAddress : Address {
|
||||||
|
this(string) {
|
||||||
|
throw new Exception("No unix address support on this system in lib yet :(");
|
||||||
|
}
|
||||||
|
override sockaddr* name() { assert(0); }
|
||||||
|
override const(sockaddr)* name() const { assert(0); }
|
||||||
|
override int nameLen() const { assert(0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Copy pasta from cgi.d, then stripped down. unix path thing added tho
|
||||||
///
|
///
|
||||||
struct Uri {
|
struct Uri {
|
||||||
alias toString this; // blargh idk a url really is a string, but should it be implicit?
|
alias toString this; // blargh idk a url really is a string, but should it be implicit?
|
||||||
|
@ -339,6 +356,18 @@ struct Uri {
|
||||||
reparse(uri);
|
reparse(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string unixSocketPath = null;
|
||||||
|
/// Indicates it should be accessed through a unix socket instead of regular tcp
|
||||||
|
void viaUnixSocket(string path) {
|
||||||
|
unixSocketPath = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Goes through a unix socket in the abstract namespace (linux only)
|
||||||
|
version(linux)
|
||||||
|
void viaAbstractSocket(string path) {
|
||||||
|
unixSocketPath = "\0" ~ path;
|
||||||
|
}
|
||||||
|
|
||||||
private void reparse(string uri) {
|
private void reparse(string uri) {
|
||||||
// from RFC 3986
|
// from RFC 3986
|
||||||
// the ctRegex triples the compile time and makes ugly errors for no real benefit
|
// the ctRegex triples the compile time and makes ugly errors for no real benefit
|
||||||
|
@ -545,6 +574,11 @@ struct Uri {
|
||||||
|
|
||||||
n.removeDots();
|
n.removeDots();
|
||||||
|
|
||||||
|
// if still basically talking to the same thing, we should inherit the unix path
|
||||||
|
// too since basically the unix path is saying for this service, always use this override.
|
||||||
|
if(n.host == baseUrl.host && n.scheme == baseUrl.scheme && n.port == baseUrl.port)
|
||||||
|
n.unixSocketPath = baseUrl.unixSocketPath;
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -630,6 +664,7 @@ class HttpRequest {
|
||||||
auto parts = where;
|
auto parts = where;
|
||||||
finalUrl = where.toString();
|
finalUrl = where.toString();
|
||||||
requestParameters.method = method;
|
requestParameters.method = method;
|
||||||
|
requestParameters.unixSocketPath = where.unixSocketPath;
|
||||||
requestParameters.host = parts.host;
|
requestParameters.host = parts.host;
|
||||||
requestParameters.port = cast(ushort) parts.port;
|
requestParameters.port = cast(ushort) parts.port;
|
||||||
requestParameters.ssl = parts.scheme == "https";
|
requestParameters.ssl = parts.scheme == "https";
|
||||||
|
@ -812,18 +847,25 @@ class HttpRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket getOpenSocketOnHost(string host, ushort port, bool ssl) {
|
Socket getOpenSocketOnHost(string host, ushort port, bool ssl, string unixSocketPath) {
|
||||||
|
|
||||||
Socket openNewConnection() {
|
Socket openNewConnection() {
|
||||||
Socket socket;
|
Socket socket;
|
||||||
if(ssl) {
|
if(ssl) {
|
||||||
version(with_openssl)
|
version(with_openssl)
|
||||||
socket = new SslClientSocket(AddressFamily.INET, SocketType.STREAM);
|
socket = new SslClientSocket(family(unixSocketPath), SocketType.STREAM);
|
||||||
else
|
else
|
||||||
throw new Exception("SSL not compiled in");
|
throw new Exception("SSL not compiled in");
|
||||||
} else
|
} else
|
||||||
socket = new Socket(AddressFamily.INET, SocketType.STREAM);
|
socket = new Socket(family(unixSocketPath), SocketType.STREAM);
|
||||||
|
|
||||||
|
if(unixSocketPath) {
|
||||||
|
socket.connect(new UnixAddress(unixSocketPath));
|
||||||
|
} else {
|
||||||
|
// FIXME: i should prolly do ipv6 if available too.
|
||||||
socket.connect(new InternetAddress(host, port));
|
socket.connect(new InternetAddress(host, port));
|
||||||
|
}
|
||||||
|
|
||||||
debug(arsd_http2) writeln("opening to ", host, ":", port, " ", cast(void*) socket);
|
debug(arsd_http2) writeln("opening to ", host, ":", port, " ", cast(void*) socket);
|
||||||
assert(socket.handle() !is socket_t.init);
|
assert(socket.handle() !is socket_t.init);
|
||||||
return socket;
|
return socket;
|
||||||
|
@ -903,7 +945,7 @@ class HttpRequest {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto socket = getOpenSocketOnHost(pc.requestParameters.host, pc.requestParameters.port, pc.requestParameters.ssl);
|
auto socket = getOpenSocketOnHost(pc.requestParameters.host, pc.requestParameters.port, pc.requestParameters.ssl, pc.requestParameters.unixSocketPath);
|
||||||
|
|
||||||
if(socket !is null) {
|
if(socket !is null) {
|
||||||
activeRequestOnSocket[socket] = pc;
|
activeRequestOnSocket[socket] = pc;
|
||||||
|
@ -1384,6 +1426,8 @@ struct HttpRequestParameters {
|
||||||
|
|
||||||
string contentType; ///
|
string contentType; ///
|
||||||
ubyte[] bodyData; ///
|
ubyte[] bodyData; ///
|
||||||
|
|
||||||
|
string unixSocketPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IHttpClient {
|
interface IHttpClient {
|
||||||
|
@ -2209,11 +2253,11 @@ wss://echo.websocket.org
|
||||||
|
|
||||||
if(ssl) {
|
if(ssl) {
|
||||||
version(with_openssl)
|
version(with_openssl)
|
||||||
socket = new SslClientSocket(AddressFamily.INET, SocketType.STREAM);
|
socket = new SslClientSocket(family(uri.unixSocketPath), SocketType.STREAM);
|
||||||
else
|
else
|
||||||
throw new Exception("SSL not compiled in");
|
throw new Exception("SSL not compiled in");
|
||||||
} else
|
} else
|
||||||
socket = new Socket(AddressFamily.INET, SocketType.STREAM);
|
socket = new Socket(family(uri.unixSocketPath), SocketType.STREAM);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2222,6 +2266,9 @@ wss://echo.websocket.org
|
||||||
+/
|
+/
|
||||||
/// Group: foundational
|
/// Group: foundational
|
||||||
void connect() {
|
void connect() {
|
||||||
|
if(uri.unixSocketPath)
|
||||||
|
socket.connect(new UnixAddress(uri.unixSocketPath));
|
||||||
|
else
|
||||||
socket.connect(new InternetAddress(host, port)); // FIXME: ipv6 support...
|
socket.connect(new InternetAddress(host, port)); // FIXME: ipv6 support...
|
||||||
// FIXME: websocket handshake could and really should be async too.
|
// FIXME: websocket handshake could and really should be async too.
|
||||||
|
|
||||||
|
@ -2924,8 +2971,8 @@ private {
|
||||||
return needsMoreData();
|
return needsMoreData();
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.data = d[0 .. msg.realLength];
|
msg.data = d[0 .. cast(size_t) msg.realLength];
|
||||||
d = d[msg.realLength .. $];
|
d = d[cast(size_t) msg.realLength .. $];
|
||||||
|
|
||||||
if(msg.masked) {
|
if(msg.masked) {
|
||||||
// let's just unmask it now
|
// let's just unmask it now
|
||||||
|
|
13
terminal.d
13
terminal.d
|
@ -190,7 +190,6 @@ version(Windows)
|
||||||
|
|
||||||
version(Win32Console) {
|
version(Win32Console) {
|
||||||
import core.sys.windows.windows;
|
import core.sys.windows.windows;
|
||||||
import std.string : toStringz;
|
|
||||||
private {
|
private {
|
||||||
enum RED_BIT = 4;
|
enum RED_BIT = 4;
|
||||||
enum GREEN_BIT = 2;
|
enum GREEN_BIT = 2;
|
||||||
|
@ -1272,8 +1271,16 @@ http://msdn.microsoft.com/en-us/library/windows/desktop/ms683193%28v=vs.85%29.as
|
||||||
/// Changes the terminal's title
|
/// Changes the terminal's title
|
||||||
void setTitle(string t) {
|
void setTitle(string t) {
|
||||||
version(Win32Console) {
|
version(Win32Console) {
|
||||||
// FIXME: use the W version
|
wchar[256] buffer;
|
||||||
SetConsoleTitleA(toStringz(t));
|
size_t bufferLength;
|
||||||
|
foreach(wchar ch; t)
|
||||||
|
if(bufferLength < buffer.length)
|
||||||
|
buffer[bufferLength++] = ch;
|
||||||
|
if(bufferLength < buffer.length)
|
||||||
|
buffer[bufferLength++] = 0;
|
||||||
|
else
|
||||||
|
buffer[$-1] = 0;
|
||||||
|
SetConsoleTitleW(buffer.ptr);
|
||||||
} else {
|
} else {
|
||||||
import std.string;
|
import std.string;
|
||||||
if(terminalInFamily("xterm", "rxvt", "screen", "tmux"))
|
if(terminalInFamily("xterm", "rxvt", "screen", "tmux"))
|
||||||
|
|
Loading…
Reference in New Issue