|
|
@@ -3,52 +3,18 @@ using Invercargill.DataStructures;
|
|
|
|
|
|
namespace Astralis {
|
|
|
|
|
|
- public class HttpResult : Object {
|
|
|
- private Catalogue<string, string> header_catalogue;
|
|
|
- public StatusCode status { get; set; }
|
|
|
+ public abstract class HttpResult : Object {
|
|
|
public Catalogue<string, string> headers { get; private set; }
|
|
|
+ public StatusCode status { get; set; }
|
|
|
+ public uint64? content_length { get; set; }
|
|
|
|
|
|
- public HttpResult(StatusCode status, Catalogue<string, string>? headers = null) {
|
|
|
- this.header_catalogue = new Catalogue<string, string>();
|
|
|
- this.headers = header_catalogue;
|
|
|
+ protected HttpResult(StatusCode status, uint64? content_length = null) {
|
|
|
+ headers = new Catalogue<string, string>();
|
|
|
this.status = status;
|
|
|
- if(headers != null) {
|
|
|
- headers.to_immutable_buffer().iterate((grouping) => {
|
|
|
- grouping.iterate((value) => {
|
|
|
- header_catalogue.add(grouping.key, value);
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void add_header(string name, string value) {
|
|
|
- header_catalogue.add(name, value);
|
|
|
- }
|
|
|
-
|
|
|
- public void add_headers(Catalogue<string, string> headers) {
|
|
|
- headers.to_immutable_buffer().iterate((grouping) => {
|
|
|
- grouping.iterate((value) => {
|
|
|
- header_catalogue.add(grouping.key, value);
|
|
|
- });
|
|
|
- });
|
|
|
+ this.content_length = content_length;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- public class BufferedHttpResult : HttpResult {
|
|
|
-
|
|
|
- public uint8[] buffer { get; set; }
|
|
|
|
|
|
- public BufferedHttpResult(uint8[] buffer, StatusCode status = StatusCode.OK, Catalogue<string, string>? headers = null) {
|
|
|
- base(status, headers);
|
|
|
- this.buffer = buffer;
|
|
|
- add_header("Content-Length", this.buffer.length.to_string());
|
|
|
- }
|
|
|
-
|
|
|
- public BufferedHttpResult.from_string(string str, StatusCode status = StatusCode.OK, Catalogue<string, string>? headers = null) {
|
|
|
- base(status, headers);
|
|
|
- this.buffer = str.data;
|
|
|
- add_header("Content-Length", this.buffer.length.to_string());
|
|
|
- }
|
|
|
+ public abstract async void send_body(AsyncOutput output) throws Error;
|
|
|
}
|
|
|
|
|
|
}
|