bug in skipping footers - caused data error

This commit is contained in:
Adam D. Ruppe 2016-03-04 19:50:48 -05:00
parent 4c178891de
commit f9bc47b0df
1 changed files with 54 additions and 10 deletions

64
http2.d
View File

@ -687,6 +687,11 @@ class HttpRequest {
//goto done; // FIXME //goto done; // FIXME
state = State.complete; state = State.complete;
// skip the tailing chunk of headers
// FIXME
if(data.length == 5 && data == [48, 13, 10, 13, 10])
a = data.length;
if(bodyReadingState.isGzipped || bodyReadingState.isDeflated) { if(bodyReadingState.isGzipped || bodyReadingState.isDeflated) {
auto n = uncompress.uncompress(responseData.content); auto n = uncompress.uncompress(responseData.content);
n ~= uncompress.flush(); n ~= uncompress.flush();
@ -753,7 +758,12 @@ class HttpRequest {
size_t bodyBytesSent; size_t bodyBytesSent;
size_t bodyBytesReceived; size_t bodyBytesReceived;
State state; State state_;
State state() { return state_; }
State state(State s) {
assert(state_ != State.complete);
return state_ = s;
}
/// Called when data is received. Check the state to see what data is available. /// Called when data is received. Check the state to see what data is available.
void delegate(HttpRequest) onDataReceived; void delegate(HttpRequest) onDataReceived;
@ -1034,13 +1044,23 @@ version(use_openssl) {
int SSL_connect(SSL*); int SSL_connect(SSL*);
int SSL_write(SSL*, const void*, int); int SSL_write(SSL*, const void*, int);
int SSL_read(SSL*, void*, int); int SSL_read(SSL*, void*, int);
int SSL_pending(const SSL*);
void SSL_free(SSL*); void SSL_free(SSL*);
void SSL_CTX_free(SSL_CTX*); void SSL_CTX_free(SSL_CTX*);
int SSL_pending(const SSL*);
void SSL_set_verify(SSL*, int, void*);
enum SSL_VERIFY_NONE = 0;
SSL_METHOD* SSLv3_client_method(); SSL_METHOD* SSLv3_client_method();
SSL_METHOD* TLS_client_method();
SSL_METHOD* SSLv23_client_method();
void ERR_print_errors_fp(FILE*);
} }
import core.stdc.stdio;
shared static this() { shared static this() {
SSL_library_init(); SSL_library_init();
OpenSSL_add_all_ciphers(); OpenSSL_add_all_ciphers();
@ -1054,11 +1074,13 @@ version(use_openssl) {
class OpenSslSocket : Socket { class OpenSslSocket : Socket {
private SSL* ssl; private SSL* ssl;
private SSL_CTX* ctx; private SSL_CTX* ctx;
private void initSsl() { private void initSsl(bool verifyPeer) {
ctx = SSL_CTX_new(SSLv3_client_method()); ctx = SSL_CTX_new(SSLv23_client_method());
assert(ctx !is null); assert(ctx !is null);
ssl = SSL_new(ctx); ssl = SSL_new(ctx);
if(!verifyPeer)
SSL_set_verify(ssl, SSL_VERIFY_NONE, null);
SSL_set_fd(ssl, this.handle); SSL_set_fd(ssl, this.handle);
} }
@ -1069,33 +1091,55 @@ version(use_openssl) {
@trusted @trusted
override void connect(Address to) { override void connect(Address to) {
super.connect(to); super.connect(to);
if(SSL_connect(ssl) == -1) if(SSL_connect(ssl) == -1) {
ERR_print_errors_fp(stderr);
int i;
printf("wtf\n");
scanf("%d\n", i);
throw new Exception("ssl connect"); throw new Exception("ssl connect");
}
} }
@trusted @trusted
override ptrdiff_t send(const(void)[] buf, SocketFlags flags) { override ptrdiff_t send(const(void)[] buf, SocketFlags flags) {
return SSL_write(ssl, buf.ptr, cast(uint) buf.length); auto retval = SSL_write(ssl, buf.ptr, cast(uint) buf.length);
if(retval == -1) {
ERR_print_errors_fp(stderr);
int i;
printf("wtf\n");
scanf("%d\n", i);
throw new Exception("ssl send");
}
return retval;
} }
override ptrdiff_t send(const(void)[] buf) { override ptrdiff_t send(const(void)[] buf) {
return send(buf, SocketFlags.NONE); return send(buf, SocketFlags.NONE);
} }
@trusted @trusted
override ptrdiff_t receive(void[] buf, SocketFlags flags) { override ptrdiff_t receive(void[] buf, SocketFlags flags) {
return SSL_read(ssl, buf.ptr, cast(int)buf.length); auto retval = SSL_read(ssl, buf.ptr, cast(int)buf.length);
if(retval == -1) {
ERR_print_errors_fp(stderr);
int i;
printf("wtf\n");
scanf("%d\n", i);
throw new Exception("ssl send");
}
return retval;
} }
override ptrdiff_t receive(void[] buf) { override ptrdiff_t receive(void[] buf) {
return receive(buf, SocketFlags.NONE); return receive(buf, SocketFlags.NONE);
} }
this(AddressFamily af, SocketType type = SocketType.STREAM) { this(AddressFamily af, SocketType type = SocketType.STREAM, bool verifyPeer = true) {
super(af, type); super(af, type);
initSsl(); initSsl(verifyPeer);
} }
this(socket_t sock, AddressFamily af) { this(socket_t sock, AddressFamily af) {
super(sock, af); super(sock, af);
initSsl(); initSsl(true);
} }
~this() { ~this() {