public void copyFrom(Request other) { this.postParams.copyFrom(other.postParams); this.headers.copyFrom(other.headers); this.httpVersion = other.httpVersion; this.method = other.method; this.socket.copyFrom(other.socket); this.url.copyFrom(other.url); this.cookies.copyFrom(other.cookies); if (other.bodyBuffer != null) { final CharBuffer otherBuffer = other.getBodyBuffer(); final CharBuffer thisBuffer = this.withBodyBuffer(); for (int i = 0; i < otherBuffer.length(); i++) { thisBuffer.append(otherBuffer.charAt(i)); } thisBuffer.flip(); } }
@Test void testBodyBuffer() throws IOException { final Transaction transaction = createTransactionWithRequiredValues(); final CharBuffer bodyBuffer = transaction.getContext().getRequest().withBodyBuffer(); IOUtils.decodeUtf8Bytes("{f".getBytes(StandardCharsets.UTF_8), bodyBuffer); IOUtils.decodeUtf8Bytes(new byte[]{0, 0, 'o', 'o', 0}, 2, 2, bodyBuffer); IOUtils.decodeUtf8Byte((byte) '}', bodyBuffer); bodyBuffer.flip(); final String content = serializer.toJsonString(transaction); System.out.println(content); final JsonNode transactionJson = objectMapper.readTree(content); assertThat(transactionJson.get("context").get("request").get("body").textValue()).isEqualTo("{foo}"); transaction.resetState(); assertThat((Object) transaction.getContext().getRequest().getBodyBuffer()).isNull(); }
@Test void testBodyBufferCopy() throws IOException { final Transaction transaction = createTransactionWithRequiredValues(); final CharBuffer bodyBuffer = transaction.getContext().getRequest().withBodyBuffer(); IOUtils.decodeUtf8Bytes("{foo}".getBytes(StandardCharsets.UTF_8), bodyBuffer); bodyBuffer.flip(); Transaction copy = createTransactionWithRequiredValues(); copy.getContext().copyFrom(transaction.getContext()); assertThat(objectMapper.readTree(serializer.toJsonString(copy)).get("context")) .isEqualTo(objectMapper.readTree(serializer.toJsonString(transaction)).get("context")); }
request.withHttpVersion("1.1"); request.withMethod("POST"); request.withBodyBuffer().append("Hello World").flip(); request.getUrl() .withProtocol("https")
request.withHttpVersion("1.1"); request.withMethod("POST"); request.withBodyBuffer().append("Hello World").flip(); request.getUrl() .withProtocol("https")