@@ -45,7 +45,7 @@ public void run() {
4545 HttpRequestBody body = requestMessage .body ();
4646 registerNewUser (body );
4747
48- responseDynamic (out );
48+ responseRedirect (out , URI . create ( "/index.html" ) );
4949 }
5050
5151 } catch (IOException e ) {
@@ -81,6 +81,13 @@ private void responseDynamic(OutputStream out) {
8181 responseBody (dos , body );
8282 }
8383
84+ private void responseRedirect (OutputStream out , URI uri ) {
85+ DataOutputStream dos = new DataOutputStream (out );
86+ byte [] body = new byte []{};
87+ response302Header (dos , uri );
88+ responseBody (dos , body );
89+ }
90+
8491 private boolean isStaticResourceRequest (URI uri ) {
8592 return !uri .getPath ().equals (USER_CREATE_URI_PATH );
8693 }
@@ -96,6 +103,16 @@ private void response200Header(DataOutputStream dos, int lengthOfBodyContent) {
96103 }
97104 }
98105
106+ private void response302Header (DataOutputStream dos , URI uri ) {
107+ try {
108+ dos .writeBytes ("HTTP/1.1 302 FOUND \r \n " );
109+ dos .writeBytes ("Location: " + uri .getPath () + "\r \n " );
110+ dos .writeBytes ("\r \n " );
111+ } catch (IOException e ) {
112+ log .error (e .getMessage ());
113+ }
114+ }
115+
99116 private void responseBody (DataOutputStream dos , byte [] body ) {
100117 try {
101118 dos .write (body , 0 , body .length );
0 commit comments