1 module mars.HttpResponse;
2 
3 import mars.ServerException;
4 
5 class HttpResponse {
6 
7 	private string url;
8 	private int statusCode;
9 	private string[string] headers;
10 	private ubyte[] responseBody;
11 	private ServerException exception;
12 	
13 	string getUrl() {
14 		return url;
15 	}
16 	
17 	int getStatusCode() {
18 		return statusCode;
19 	}
20 	
21 	string[string] getHeaders() {
22 		return headers;
23 	}
24 	
25 	ubyte[] getResponseBody() {
26 		return responseBody;
27 	}
28 
29 	string getResponseBodyString() {
30         return cast(string)responseBody;
31     }
32 	
33 	ServerException getException() {
34 		return exception;
35 	}
36 	
37 	private this(Builder builder) {
38 		url = builder.mUrl;
39 		statusCode = builder.mStatusCode;
40 		headers = builder.mHeaders;
41 		responseBody = builder.mResponseBody;
42 		exception = builder.mException;
43 	}
44 	
45 	static class Builder {
46 		private string mUrl;
47 		private int mStatusCode;
48 		private string[string] mHeaders;
49 		private ubyte[] mResponseBody;
50 		private ServerException mException;
51 
52 		Builder url(string value) {
53 			mUrl = value;
54 			return this;
55 		}
56 		
57 		Builder statusCode(int value) {
58 			mStatusCode = value;
59 			return this;
60 		}
61 		
62 		Builder headers(string[string] value) {
63 			mHeaders = value;
64 			return this;
65 		}
66 		
67 		Builder responseBody(ubyte[] value) {
68 			mResponseBody = value;
69 			return this;
70 		}
71 		
72 		Builder exception(ServerException value) {
73 			mException = value;
74 			return this;
75 		}
76 
77 		HttpResponse build() {
78 			return new HttpResponse(this);
79 		}
80 	}
81 }