### Question:
HttpRequestEncoder extends HttpObjectEncoder<HttpRequest> { @Override protected void encodeInitialLine(ByteBuf buf, HttpRequest request) throws Exception { request.getMethod().encode(buf); buf.writeByte(SP); String uri = request.getUri(); if (uri.length() == 0) { uri += SLASH; } else { int start = uri.indexOf(": if (start != -1 && uri.charAt(0) != SLASH) { int startIndex = start + 3; if (uri.lastIndexOf(SLASH) <= startIndex) { uri += SLASH; } } } buf.writeBytes(uri.getBytes(CharsetUtil.UTF_8)); buf.writeByte(SP); request.getProtocolVersion().encode(buf); buf.writeBytes(CRLF); }  @Override boolean acceptOutboundMessage(Object msg);  }### Answer:
@Test public void testUriWithoutPath() throws Exception { HttpRequestEncoder encoder = new HttpRequestEncoder(); ByteBuf buffer = Unpooled.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(); ByteBuf buffer = Unpooled.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 testAbsPath() throws Exception { HttpRequestEncoder encoder = new HttpRequestEncoder(); ByteBuf buffer = Unpooled.buffer(64); encoder.encodeInitialLine(buffer, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/")); String req = buffer.toString(Charset.forName("US-ASCII")); assertEquals("GET / HTTP/1.1\r\n", req); }
@Test public void testEmptyAbsPath() throws Exception { HttpRequestEncoder encoder = new HttpRequestEncoder(); ByteBuf buffer = Unpooled.buffer(64); encoder.encodeInitialLine(buffer, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "")); String req = buffer.toString(Charset.forName("US-ASCII")); assertEquals("GET / HTTP/1.1\r\n", req); }
@Test public void testQueryStringPath() throws Exception { HttpRequestEncoder encoder = new HttpRequestEncoder(); ByteBuf buffer = Unpooled.buffer(64); encoder.encodeInitialLine(buffer, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/?url=http: String req = buffer.toString(Charset.forName("US-ASCII")); assertEquals("GET /?url=http: }