Source:
<code>public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { if (request instanceof HttpEntityEnclosingRequest) { HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); byte[] inBytes = EntityUtils.toByteArray(entity); <START> TTransport input = new TMemoryInputTransport(Arrays.copyOfRange(inBytes, 4, inBytes.length)); <END> TMemoryBuffer output = new TMemoryBuffer(inBytes.length); try { processor.process(inputProtoFactory.getProtocol(input), outputProtoFactory.getProtocol(output)); } catch (TException e) { LOGGER.warn("error processing frame, discarding: " + e.getMessage()); return; } if (output.length() == 0) { return; } byte[] outBytes = new byte[output.length() + 4]; ProtocolUtils.writeInt(output.length(), outBytes, 0); System.arraycopy(output.getArray(), 0, outBytes, 4, output.length()); response.setStatusLine(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); response.setHeader("accept", "application/x-frugal"); response.setHeader("content-transfer-encoding", "base64"); response.setEntity(new ByteArrayEntity(outBytes)); } }</code><technical_language>Do need base64 decode input here? apache magically handle based headers</technical_language>

Target:
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { if (!(request instanceof HttpEntityEnclosingRequest)) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); response.setReasonPhrase("BAD REQUEST"); return; } HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); byte[] inBytes = Base64.decodeBase64(EntityUtils.toByteArray(entity)); EntityUtils.consume(entity); if ((requestSizeLimit > 0) && (inBytes.length > requestSizeLimit)) { response.setStatusCode(HttpStatus.SC_REQUEST_TOO_LONG); response.setReasonPhrase("PAYLOAD TOO LARGE"); return; } TTransport input = new TMemoryInputTransport(Arrays.copyOfRange(inBytes, 4, inBytes.length)); TMemoryBuffer output = new TMemoryBuffer(inBytes.length); try { processor.process(inputProtoFactory.getProtocol(input), outputProtoFactory.getProtocol(output)); } catch (TException e) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); response.setReasonPhrase("BAD REQUEST"); return; } Header payloadLimit = request.getFirstHeader(HttpHeaders.X_FRUGAL_PAYLOAD_LIMIT_HEADER); if (payloadLimit != null) { Integer limit = Integer.parseInt(payloadLimit.getValue()); if (output.getArray().length > limit) { response.setStatusCode(HttpStatus.SC_FORBIDDEN); response.setReasonPhrase("FORBIDDEN"); return; } } byte[] outBytes = new byte[output.length() + 4]; ProtocolUtils.writeInt(output.length(), outBytes, 0); System.arraycopy(output.getArray(), 0, outBytes, 4, output.length()); response.setStatusCode(HttpStatus.SC_OK); response.setReasonPhrase("OK"); response.setHeader(HttpHeaders.ACCEPT_HEADER, HttpHeaders.APPLICATION_X_FRUGAL_HEADER); response.setHeader(HttpHeaders.CONTENT_TRANSFER_ENCODING_HEADER, HttpHeaders.CONTENT_TRANSFER_ENCODING); response.setEntity(new StringEntity(Base64.encodeBase64String(outBytes), ContentType.create(HttpHeaders.APPLICATION_X_FRUGAL_HEADER, HttpHeaders.CONTENT_TYPE))); }