Skip to content

Commit

Permalink
fix marshall request with utf8 path (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
aajtodd authored Nov 30, 2021
1 parent c6ee722 commit 508f306
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ public HttpRequestBodyStream getBodyStream() {
public byte[] marshalForJni() {
int size = 0;
size += BUFFER_INT_SIZE + method.length();
size += BUFFER_INT_SIZE + encodedPath.length();

byte[] pathBytes = encodedPath.getBytes(UTF8);
size += BUFFER_INT_SIZE + pathBytes.length;

for (HttpHeader header : headers) {
if (header.getNameBytes().length > 0) {
Expand All @@ -176,8 +178,8 @@ public byte[] marshalForJni() {
ByteBuffer buffer = ByteBuffer.allocate(size);
buffer.putInt(method.length());
buffer.put(method.getBytes(UTF8));
buffer.putInt(encodedPath.length());
buffer.put(encodedPath.getBytes(UTF8));
buffer.putInt(pathBytes.length);
buffer.put(pathBytes);

for (HttpHeader header : headers) {
if (header.getNameBytes().length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static software.amazon.awssdk.crt.utils.ByteBufferUtils.transferData;

import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
import software.amazon.awssdk.crt.CRT;
import software.amazon.awssdk.crt.CrtResource;
Expand All @@ -25,7 +24,6 @@
import software.amazon.awssdk.crt.io.HostResolver;
import software.amazon.awssdk.crt.io.SocketOptions;
import software.amazon.awssdk.crt.io.TlsContext;
import software.amazon.awssdk.crt.io.TlsContextOptions;

import java.net.URI;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -445,4 +443,9 @@ public void onResponseComplete(HttpStream stream, int errorCode) {
CrtResource.waitForNoResources();
}

@Test
public void testMarshallJniUtf8Path() throws Exception {
HttpRequest request = new HttpRequest("GET", "/?ሴ=bar");
request.marshalForJni();
}
}

0 comments on commit 508f306

Please sign in to comment.