Explorar el Código

Update result

Billy Barrow hace 4 semanas
padre
commit
601f9b1489
Se han modificado 2 ficheros con 9 adiciones y 41 borrados
  1. 2 0
      src/Core/Context.vala
  2. 7 41
      src/Core/Response.vala

+ 2 - 0
src/Core/Context.vala

@@ -172,7 +172,9 @@ namespace Astralis {
         }
     }
 
+
     public class HttpContext : Object {
+
         public HttpRequest request { get; private set; }
 
         internal HttpContext(HttpRequest request) {

+ 7 - 41
src/Core/Response.vala

@@ -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;
     }
 
 }