From 98200f357d33049cb773c80f451e72f779fbd1c9 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Mon, 5 Feb 2018 14:39:08 -0500 Subject: [PATCH] lots of little fixes --- dom.d | 9 +-------- http2.d | 46 ++++++++++++++++++++++++++++++++++++---------- web.d | 5 +++-- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/dom.d b/dom.d index 09452a7..da132bc 100644 --- a/dom.d +++ b/dom.d @@ -3177,7 +3177,7 @@ class Element { // for simple `texttext`, let's // just keep them on the same line - if(allAreInlineHtml(children)) { + if(tagName.isInArray(inlineElements) || allAreInlineHtml(children)) { foreach(child; children) { s ~= child.toString(); } @@ -7051,13 +7051,6 @@ unittest { } +/ -/+ - so this currently outputs - - - - for an empty span. idk if i want that. -+/ bool allAreInlineHtml(const(Element)[] children) { foreach(child; children) { if(child.nodeType == NodeType.Text && child.nodeValue.strip.length) { diff --git a/http2.d b/http2.d index ff87a88..1b16bf9 100644 --- a/http2.d +++ b/http2.d @@ -59,6 +59,7 @@ version(with_openssl) { HttpRequest httpRequest(string method, string url, ubyte[] content, string[string] content) { return null; } ++/ /** auto request = get("http://arsdnet.net/"); @@ -67,16 +68,19 @@ HttpRequest httpRequest(string method, string url, ubyte[] content, string[strin auto response = get("http://arsdnet.net/").waitForCompletion(); */ HttpRequest get(string url) { - auto request = new HttpRequest(); + auto client = new HttpClient(); + auto request = client.navigateTo(Uri(url)); return request; } +/// gets the text off a url. basic operation only. string getText(string url) { auto request = get(url); auto response = request.waitForCompletion(); return cast(string) response.content; } +/+ ubyte[] getBinary(string url, string[string] cookies = null) { auto hr = httpRequest("GET", url, null, cookies); if(hr.code != 200) @@ -116,6 +120,7 @@ string post(string url, string[string] args, string[string] cookies = null) { return cast(string) hr.content; } + +/ /// @@ -667,6 +672,8 @@ class HttpRequest { import std.zlib; UnCompress uncompress; + const(ubyte)[] leftoverDataFromLastTime; + void handleIncomingData(scope const ubyte[] dataIn) { debug(arsd_http2) writeln("handleIncomingData, state: ", state); if(state == State.waitingForResponse) { @@ -675,7 +682,11 @@ class HttpRequest { bodyReadingState = BodyReadingState.init; } - const(ubyte)[] data = dataIn[]; + const(ubyte)[] data; + if(leftoverDataFromLastTime.length) + data = leftoverDataFromLastTime ~ dataIn[]; + else + data = dataIn[]; if(state == State.readingHeaders) { void parseLastHeader() { @@ -832,8 +843,9 @@ class HttpRequest { power *= 16; } debug(arsd_http2) writeln("Chunk length: ", bodyReadingState.contentLengthRemaining); - bodyReadingState.chunkedState++; - continue; + bodyReadingState.chunkedState = 1; + data = data[a + 1 .. $]; + goto start_over; } break; case 1: // reading until end of line @@ -844,31 +856,36 @@ class HttpRequest { else bodyReadingState.chunkedState = 2; } + data = data[a + 1 .. $]; + goto start_over; break; case 2: // reading data auto can = a + bodyReadingState.contentLengthRemaining; if(can > data.length) can = cast(int) data.length; + auto newData = data[a .. can]; + data = data[can .. $]; + //if(bodyReadingState.isGzipped || bodyReadingState.isDeflated) // responseData.content ~= cast(ubyte[]) uncompress.uncompress(data[a .. can]); //else - responseData.content ~= data[a .. can]; + responseData.content ~= newData; - bodyReadingState.contentLengthRemaining -= can - a; + bodyReadingState.contentLengthRemaining -= newData.length; debug(arsd_http2) writeln("clr: ", bodyReadingState.contentLengthRemaining, " " , a, " ", can); - a += can - a; assert(bodyReadingState.contentLengthRemaining >= 0); if(bodyReadingState.contentLengthRemaining == 0) { - bodyReadingState.chunkedState++; - data = data[a .. $]; + bodyReadingState.chunkedState = 3; } else { - data = data[a .. $]; + // will continue grabbing more } goto start_over; case 3: // reading 13/10 assert(data[a] == 13); bodyReadingState.chunkedState++; + data = data[a + 1 .. $]; + goto start_over; break; case 4: // reading 10 at end of packet assert(data[a] == 10); @@ -879,6 +896,8 @@ class HttpRequest { //goto done; // FIXME state = State.complete; + bodyReadingState.chunkedState = 0; + // skip the tailing chunk of headers // FIXME if(data.length == 5 && data == [48, 13, 10, 13, 10]) @@ -893,6 +912,8 @@ class HttpRequest { // responseData.content ~= cast(ubyte[]) uncompress.flush(); responseData.contentText = cast(string) responseData.content; + + goto done; } } @@ -922,6 +943,11 @@ class HttpRequest { } } } + + if(data.length) + leftoverDataFromLastTime = data.dup; + else + leftoverDataFromLastTime = null; } this() { diff --git a/web.d b/web.d index f3867d7..d8a56fd 100644 --- a/web.d +++ b/web.d @@ -1464,8 +1464,9 @@ void run(Provider)(Cgi cgi, Provider instantiation, size_t pathInfoStartingPoint } auto code = Element.make("div"); code.addClass("exception-error-message"); - code.addChild("p", e.msg); - debug code.addChild("pre", e.toString()); + import arsd.characterencodings; + code.addChild("p", convertToUtf8Lossy(cast(immutable(ubyte)[]) e.msg, "utf8")); + debug code.addChild("pre", convertToUtf8Lossy(cast(immutable(ubyte)[]) e.toString(), "utf8")); result.result.str = (code.toString()); }