1 module requests.base;
2 
3 import requests.streams;
4 import requests.utils;
5 import requests.uri;
6 
7 public class RequestException: Exception {
8     this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) @safe pure nothrow {
9         super(msg, file, line, next);
10     }
11 }
12 
13 public struct ReceiveAsRange {
14     bool empty() {
15         return data.length == 0;
16     };
17     ubyte[] front() {
18         return data;
19     };
20     void popFront() {
21         if ( read ) {
22             // get new portion
23             data = read();
24         } else {
25             // we can't read any new data
26             data.length = 0;
27         }
28     };
29     package {
30         bool            activated;
31         ubyte[]         data;
32         ubyte[]         delegate() read;
33     }
34 }
35 
36 public class Response {
37     package {
38         ushort           _code;
39         Buffer!ubyte     _responseBody;
40         string[string]   _responseHeaders;
41         /// Initial URI
42         URI              _uri;
43         /// Final URI. Can differ from __URI if request go through redirections.
44         URI              _finalURI;
45         ReceiveAsRange   _receiveAsRange;
46         mixin(Setter!ushort("code"));
47         mixin(Setter!URI("uri"));
48         mixin(Setter!URI("finalURI"));
49     }
50     mixin(Getter!ushort("code"));
51     mixin(Getter!URI("uri"));
52     mixin(Getter!URI("finalURI"));
53     @property auto ref responseBody() @safe nothrow {
54         return _responseBody;
55     }
56     @property auto ref responseHeaders() pure @safe nothrow {
57         return _responseHeaders;
58     }
59     @property auto ref receiveAsRange() pure @safe nothrow {
60         return _receiveAsRange;
61     }
62 }