if (decoder != null) {
decoder.cleanFiles();
decoder = null;
}
HttpRequest request = this.request = (HttpRequest) e.getMessage();
URI uri = new URI(request.getUri());
if (!uri.getPath().startsWith("/form")) {
// Write Menu
writeMenu(e);
return;
}
responseContent.setLength(0);
responseContent.append("WELCOME TO THE WILD WILD WEB SERVER\r\n");
responseContent.append("===================================\r\n");
responseContent.append("VERSION: " +
request.getProtocolVersion().getText() + "\r\n");
responseContent.append("REQUEST_URI: " + request.getUri() +
"\r\n\r\n");
responseContent.append("\r\n\r\n");
// new method
List<Entry<String, String>> headers = request.getHeaders();
for (Entry<String, String> entry: headers) {
responseContent.append("HEADER: " + entry.getKey() + "=" +
entry.getValue() + "\r\n");
}
responseContent.append("\r\n\r\n");
// new method
Set<Cookie> cookies;
String value = request.getHeader(HttpHeaders.Names.COOKIE);
if (value == null) {
cookies = Collections.emptySet();
} else {
CookieDecoder decoder = new CookieDecoder();
cookies = decoder.decode(value);
}
for (Cookie cookie: cookies) {
responseContent.append("COOKIE: " + cookie.toString() + "\r\n");
}
responseContent.append("\r\n\r\n");
QueryStringDecoder decoderQuery = new QueryStringDecoder(request
.getUri());
Map<String, List<String>> uriAttributes = decoderQuery
.getParameters();
for (String key: uriAttributes.keySet()) {
for (String valuen: uriAttributes.get(key)) {
responseContent.append("URI: " + key + "=" + valuen +
"\r\n");
}
}
responseContent.append("\r\n\r\n");
// if GET Method: should not try to create a HttpPostRequestDecoder
try {
decoder = new HttpPostRequestDecoder(factory, request);
} catch (ErrorDataDecoderException e1) {
e1.printStackTrace();
responseContent.append(e1.getMessage());
writeResponse(e.getChannel());
Channels.close(e.getChannel());
return;
} catch (IncompatibleDataDecoderException e1) {
// GET Method: should not try to create a HttpPostRequestDecoder
// So OK but stop here
responseContent.append(e1.getMessage());
responseContent.append("\r\n\r\nEND OF GET CONTENT\r\n");
writeResponse(e.getChannel());
return;
}
responseContent.append("Is Chunked: " + request.isChunked() +
"\r\n");
responseContent.append("IsMultipart: " + decoder.isMultipart() +
"\r\n");
if (request.isChunked()) {
// Chunk version
responseContent.append("Chunks: ");
readingChunks = true;
} else {
// Not chunk version