### Question:
HttpRequestEncoder extends HttpMessageEncoder { @Override protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception { HttpRequest request = (HttpRequest) message; buf.writeBytes(request.getMethod().toString().getBytes("ASCII")); buf.writeByte(SP); String uri = request.getUri(); int start = uri.indexOf(": if (start != -1) { int startIndex = start + 3; if (uri.lastIndexOf(SLASH) <= startIndex) { uri += SLASH; } } buf.writeBytes(uri.getBytes("UTF-8")); buf.writeByte(SP); buf.writeBytes(request.getProtocolVersion().toString().getBytes("ASCII")); buf.writeByte(CR); buf.writeByte(LF); }    }### Answer:
@Test public void testUriWithoutPath() throws Exception { HttpRequestEncoder encoder = new HttpRequestEncoder(); ChannelBuffer buffer = ChannelBuffers.buffer(64); encoder.encodeInitialLine(buffer, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http: String req = buffer.toString(Charset.forName("US-ASCII")); assertEquals("GET http: }
@Test public void testUriWithPath() throws Exception { HttpRequestEncoder encoder = new HttpRequestEncoder(); ChannelBuffer buffer = ChannelBuffers.buffer(64); encoder.encodeInitialLine(buffer, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http: String req = buffer.toString(Charset.forName("US-ASCII")); assertEquals("GET http: }