// @checkstyle ParameterNumber (7 lines)
 @Override
 public Response send(
     final Request req,
     final String home,
     final String method,
     final Collection<Map.Entry<String, String>> headers,
     final InputStream content)
     throws IOException {
   final ByteArrayOutputStream output = new ByteArrayOutputStream();
   final byte[] buffer = new byte[Tv.THOUSAND];
   for (int bytes = content.read(buffer); bytes != -1; bytes = content.read(buffer)) {
     output.write(buffer, 0, bytes);
   }
   output.flush();
   final Response response =
       this.origin.send(
           req, home, method, headers, new ByteArrayInputStream(output.toByteArray()));
   final StringBuilder text = new StringBuilder(0);
   for (final Map.Entry<String, String> header : headers) {
     text.append(header.getKey()).append(": ").append(header.getValue()).append('\n');
   }
   text.append('\n').append(new RequestBody.Printable(output.toByteArray()).toString());
   Logger.info(
       this,
       "#send(%s %s):\nHTTP Request (%s):\n%s\nHTTP Response (%s):\n%s",
       method,
       home,
       req.getClass().getName(),
       VerboseWire.indent(text.toString()),
       response.getClass().getName(),
       VerboseWire.indent(response.toString()));
   return response;
 }
Beispiel #2
0
 /**
  * Creates the response received from the target host.
  *
  * @param home Home host
  * @param dest Destination URL
  * @param rsp Response received from the target host
  * @return Response
  */
 private Response response(final String home, final URI dest, final com.jcabi.http.Response rsp) {
   final Collection<String> hdrs = new LinkedList<String>();
   hdrs.add(String.format("X-Takes-TkProxy: from %s to %s by %s", home, dest, this.label));
   for (final Map.Entry<String, List<String>> entry : rsp.headers().entrySet()) {
     for (final String value : entry.getValue()) {
       final String val;
       if (TkProxy.isHost(entry.getKey())) {
         val = this.target.toString();
       } else {
         val = value;
       }
       hdrs.add(String.format("%s: %s", entry.getKey(), val));
     }
   }
   return new RsWithStatus(
       new RsWithBody(new RsWithHeaders(hdrs), rsp.binary()), rsp.status(), rsp.reason());
 }