1 module hunt.framework.http.RedirectResponse;
2 
3 import hunt.framework.http.Response;
4 
5 import hunt.Exceptions;
6 import hunt.http.server;
7 import hunt.logging.ConsoleLogger;
8 
9 
10 import std.conv;
11 import std.datetime;
12 import std.json;
13 
14 
15 // import hunt.framework.util.String;
16 // import hunt.framework.Version;
17 // import hunt.framework.http.Response;
18 import hunt.framework.http.Request;
19 // import hunt.framework.http.session;
20 // import hunt.framework.Exceptions;
21 
22 /**
23  * RedirectResponse represents an HTTP response doing a redirect.
24  *
25  */
26 class RedirectResponse : Response {
27 
28     private Request _request;
29 
30     // this(string targetUrl, bool use301 = false) {
31     //     setStatus((use301 ? 301 : 302));
32     //     header(HttpHeader.LOCATION, targetUrl);
33     //     // connectionClose();
34     // }
35 
36     this(Request request, string targetUrl, bool use301 = false) {
37         // super(request());
38         super();
39         _request = request;
40 
41         setStatus((use301 ? 301 : 302));
42         header(HttpHeader.LOCATION, targetUrl);
43         // connectionClose();
44     }
45 
46     private HttpSession session() {
47         return _request.session();
48     }
49 
50     /**
51      * Flash a piece of data to the session.
52      *
53      * @param  string|array  key
54      * @param  mixed  value
55      * @return RedirectResponse
56      */
57     RedirectResponse withSession(string key, string value) {
58         session.flash(key, value);
59         return this;
60     }
61 
62     /// ditto
63     RedirectResponse withSession(string[string] sessions) {
64         foreach (string key, string value; sessions) {
65             session.flash(key, value);
66         }
67         return this;
68     }
69 
70     /**
71      * Flash an array of input to the session.
72      *
73      * @param  array  input
74      * @return this
75      */
76     RedirectResponse withInput(string[string] input = null) {
77         session.flashInput(input is null ? _request.input() : input);
78         return this;
79     }
80 
81     /**
82      * Remove all uploaded files form the given input array.
83      *
84      * @param  array  input
85      * @return array
86      */
87     // protected string[string] removeFilesFromInput(string[string] input)
88     // {
89     //     throw new NotImplementedException("removeFilesFromInput");
90     // }
91 
92     /**
93      * Flash an array of input to the session.
94      *
95      * @return this
96      */
97     // RedirectResponse onlyInput(string[] keys...)
98     // {
99     //     return withInput(_request.only(keys));
100     // }
101 
102     /**
103      * Flash an array of input to the session.
104      *
105      * @return this
106      */
107     // RedirectResponse exceptInput(string[] keys...)
108     // {
109     //     return withInput(_request.except(keys));
110     // }
111 
112     /**
113      * Get the original response content.
114      *
115      * @return null
116      */
117     // override const(ubyte)[] getOriginalContent()
118     // {
119     //     return null;
120     // }
121 }