HttpResponse extends MessageImpl { public byte[] statusLineAndHeadersToWireFormat() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { baos.write(getHttpVersion().getBytes()); baos.write(' '); baos.write(Integer.toString(statusCode.getStatusCode()).getBytes()); baos.write(' '); baos.write(statusCode.getReasonPhrase().getBytes()); baos.write('\r'); baos.write('\n'); for(HttpHeader h: getHeaders()) { baos.write(h.toWireFormat()); baos.write('\r'); baos.write('\n'); } baos.write('\r'); baos.write('\n'); } catch(IOException e) { throw new IllegalArgumentException("internal error", e); } return baos.toByteArray(); } HttpResponse();  HttpResponse(HttpStatusCode statusCode);  HttpResponse(HttpStatusCode statusCode, byte[] entityBodyContent);  HttpResponse(byte[] wireContent); static String showResponse(HttpResponse r); HttpStatusCode getStatusCode(); void setStatusCode(HttpStatusCode c); String getHttpVersion(); void setRequest(HttpRequest r); HttpRequest getRequest(); byte[] statusLineAndHeadersToWireFormat(); @Override String toString();  }
@Test public void statusLineAndHeadersToWireFormat() throws Exception { HttpResponse r = new HttpResponse(); r.setStatusCode(HttpStatusCode.OK); r.addHeader(HttpResponseHeader.SERVER, "NovaOrdis http-server"); r.addHeader("Some-Random-Header", "something"); byte[] b = r.statusLineAndHeadersToWireFormat(); String s = new String(b); log.info(s); String expected = "HTTP/1.1 200 OK\r\n" + "Server: NovaOrdis http-server\r\n" + "Some-Random-Header: something\r\n" + "\r\n"; assertEquals(expected, s); }