mirror of https://github.com/adamdruppe/arsd.git
use std.socket instead, now should work on Windows
This commit is contained in:
parent
1ad4d9f013
commit
2e06cbdcc5
17
http.d
17
http.d
|
@ -1,7 +1,5 @@
|
||||||
module arsd.http;
|
module arsd.http;
|
||||||
|
|
||||||
import std.stdio;
|
|
||||||
|
|
||||||
version(with_openssl) {
|
version(with_openssl) {
|
||||||
pragma(lib, "crypto");
|
pragma(lib, "crypto");
|
||||||
pragma(lib, "ssl");
|
pragma(lib, "ssl");
|
||||||
|
@ -105,16 +103,21 @@ struct UriParts {
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponse httpRequest(string method, string uri, const(ubyte)[] content = null, string headers[] = null) {
|
HttpResponse httpRequest(string method, string uri, const(ubyte)[] content = null, string headers[] = null) {
|
||||||
|
import std.socket;
|
||||||
|
|
||||||
auto u = UriParts(uri);
|
auto u = UriParts(uri);
|
||||||
auto f = openNetwork(u.host, u.port);
|
// auto f = openNetwork(u.host, u.port);
|
||||||
|
auto f = new TcpSocket();
|
||||||
|
f.connect(new InternetAddress(u.host, u.port));
|
||||||
|
|
||||||
void delegate(string) write = (string d) {
|
void delegate(string) write = (string d) {
|
||||||
f.rawWrite(d);
|
f.send(d);
|
||||||
};
|
};
|
||||||
|
|
||||||
char[1] readBuffer; // rawRead actually blocks until it can fill up the whole buffer... which is broken as far as http goes so one char at a time i guess. slow lol
|
char[4096] readBuffer; // rawRead actually blocks until it can fill up the whole buffer... which is broken as far as http goes so one char at a time i guess. slow lol
|
||||||
char[] delegate() read = () {
|
char[] delegate() read = () {
|
||||||
return f.rawRead(readBuffer);
|
int num = f.receive(readBuffer);
|
||||||
|
return readBuffer[0..num];
|
||||||
};
|
};
|
||||||
|
|
||||||
version(with_openssl) {
|
version(with_openssl) {
|
||||||
|
@ -135,7 +138,7 @@ HttpResponse httpRequest(string method, string uri, const(ubyte)[] content = nul
|
||||||
sslAssert(!(ctx is null));
|
sslAssert(!(ctx is null));
|
||||||
|
|
||||||
ssl = SSL_new(ctx);
|
ssl = SSL_new(ctx);
|
||||||
SSL_set_fd(ssl, f.fileno);
|
SSL_set_fd(ssl, f.handle);
|
||||||
sslAssert(SSL_connect(ssl) != -1);
|
sslAssert(SSL_connect(ssl) != -1);
|
||||||
|
|
||||||
write = (string d) {
|
write = (string d) {
|
||||||
|
|
Loading…
Reference in New Issue