mirror of https://github.com/adamdruppe/arsd.git
mime type convenience accessor
This commit is contained in:
parent
f7f3076604
commit
ff307389dd
29
http2.d
29
http2.d
|
@ -226,7 +226,7 @@ struct HttpResponse {
|
||||||
|
|
||||||
string statusLine; ///
|
string statusLine; ///
|
||||||
|
|
||||||
string contentType; /// The content type header
|
string contentType; /// The *full* content type header. See also [contentTypeMimeType] and [contentTypeCharset].
|
||||||
string location; /// The location header
|
string location; /// The location header
|
||||||
|
|
||||||
/++
|
/++
|
||||||
|
@ -238,6 +238,20 @@ struct HttpResponse {
|
||||||
return code >= 200 && code < 400;
|
return code >= 200 && code < 400;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/++
|
||||||
|
Returns the mime type part of the [contentType] header.
|
||||||
|
|
||||||
|
History:
|
||||||
|
Added July 25, 2022 (version 10.9)
|
||||||
|
+/
|
||||||
|
string contentTypeMimeType() {
|
||||||
|
auto idx = contentType.indexOf(";");
|
||||||
|
if(idx == -1)
|
||||||
|
return contentType;
|
||||||
|
|
||||||
|
return contentType[0 .. idx].strip;
|
||||||
|
}
|
||||||
|
|
||||||
/// the charset out of content type, if present. `null` if not.
|
/// the charset out of content type, if present. `null` if not.
|
||||||
string contentTypeCharset() {
|
string contentTypeCharset() {
|
||||||
auto idx = contentType.indexOf("charset=");
|
auto idx = contentType.indexOf("charset=");
|
||||||
|
@ -1365,7 +1379,7 @@ class HttpRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(arsd_http2) writeln("opening to ", host, ":", port, " ", cast(void*) socket);
|
debug(arsd_http2) writeln("opening to ", host, ":", port, " ", cast(void*) socket, " ssl=", ssl);
|
||||||
assert(socket.handle() !is socket_t.init);
|
assert(socket.handle() !is socket_t.init);
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
@ -1667,9 +1681,12 @@ class HttpRequest {
|
||||||
request.sendBuffer = request.sendBuffer[sent .. $];
|
request.sendBuffer = request.sendBuffer[sent .. $];
|
||||||
if(request.sendBuffer.length == 0) {
|
if(request.sendBuffer.length == 0) {
|
||||||
request.state = State.waitingForResponse;
|
request.state = State.waitingForResponse;
|
||||||
|
|
||||||
|
debug(arsd_http2_verbose) writeln("all sent");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(readSet.isSet(sock)) {
|
if(readSet.isSet(sock)) {
|
||||||
keep_going:
|
keep_going:
|
||||||
request.timeoutFromInactivity = MonoTime.currTime + request.requestParameters.timeoutFromInactivity;
|
request.timeoutFromInactivity = MonoTime.currTime + request.requestParameters.timeoutFromInactivity;
|
||||||
|
@ -1695,6 +1712,14 @@ class HttpRequest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
stillAlive = request.handleIncomingData(buffer[0 .. got]);
|
stillAlive = request.handleIncomingData(buffer[0 .. got]);
|
||||||
|
/+
|
||||||
|
state needs to be set and public
|
||||||
|
requestData.content/contentText needs to be around
|
||||||
|
you need to be able to clear the content and keep processing for things like event sources.
|
||||||
|
also need to be able to abort it.
|
||||||
|
|
||||||
|
and btw it should prolly just have evnet source as a pre-packaged thing.
|
||||||
|
+/
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
request.state = HttpRequest.State.aborted;
|
request.state = HttpRequest.State.aborted;
|
||||||
request.responseData.code = 4;
|
request.responseData.code = 4;
|
||||||
|
|
Loading…
Reference in New Issue