ChannelFuture future = channel.write(writeBuffer);
if (releaseContentListener != null) {
future.addListener(releaseContentListener);
}
} catch (Exception e) {
throw new MemcachedTransportException("Failed to write response", e);
}
} else {
if (response.status().getStatus() >= 500) {
channel.write(ERROR.duplicate());
} else {
if (request.method() == RestRequest.Method.POST) {
// TODO this is SET, can we send a payload?
channel.write(STORED.duplicate());
} else if (request.method() == RestRequest.Method.DELETE) {
channel.write(DELETED.duplicate());
} else { // GET
try {
ChannelBuffer writeBuffer = ChannelBuffers.dynamicBuffer(response.content().length() + 512);
writeBuffer.writeBytes(VALUE.duplicate());
BytesRef bytesRef = new BytesRef(request.uri());
writeBuffer.writeBytes(bytesRef.bytes, bytesRef.offset, bytesRef.length);
writeBuffer.writeByte(' ');
writeBuffer.writeByte('0');
writeBuffer.writeByte(' ');
writeBuffer.writeBytes(Bytes.itoa(response.content().length()));
writeBuffer.writeByte('\r');
writeBuffer.writeByte('\n');
writeBuffer.writeBytes(response.content().toBytes(), 0, response.content().length());
writeBuffer.writeByte('\r');
writeBuffer.writeByte('\n');
writeBuffer.writeBytes(END.duplicate());
channel.write(writeBuffer);
} catch (Exception e) {
throw new MemcachedTransportException("Failed to write 'get' response", e);
}
}
}
}
}