You send the response header right before the body:
PrintWriter writer = new PrintWriter(socket.getOutputStream());
writer.println("HTTP/1.0 200 Ok");
writer.println("Set-Cookie key=value Max-Age=8640");
writer.println("Content-Type text/html");
writer.println()//important
//send your body here
writer.flush();//send message
Here's a list of HTTP response header fields https://en.wikipedia.org/wiki/List_of_HTTP_header_fields