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 (Entry<String, List<String>> attr: uriAttributes.entrySet()) {
for (String attrVal: attr.getValue()) {
responseContent.append("URI: " + attr.getKey() + '=' + attrVal + "\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
readHttpDataAllReceive(e.getChannel());
responseContent
.append("\r\n\r\nEND OF NOT CHUNKED CONTENT\r\n");
writeResponse(e.getChannel());
}
} else {
// New chunk is received
HttpChunk chunk = (HttpChunk) e.getMessage();
try {
decoder.offer(chunk);
} catch (ErrorDataDecoderException e1) {
e1.printStackTrace();
responseContent.append(e1.getMessage());
writeResponse(e.getChannel());
Channels.close(e.getChannel());