Skip to content

Commit b59092c

Browse files
authored
fix the HTTP test (#892)
1 parent b7dec97 commit b59092c

3 files changed

Lines changed: 43 additions & 29 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ jobs:
199199
./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-${{ matrix.image }} build -p ${{ env.PACKAGE_NAME }}
200200
201201
windows:
202-
runs-on: windows-2022 # latest
202+
runs-on: windows-2025 # latest
203203
steps:
204204
- uses: aws-actions/configure-aws-credentials@v4
205205
with:
@@ -214,8 +214,8 @@ jobs:
214214
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
215215
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --spec=downstream
216216
217-
windows-vc14:
218-
runs-on: windows-2019 # windows-2019 is last env with Visual Studio 2015 (v14.0)
217+
windows-vc17:
218+
runs-on: windows-2025 # latest
219219
strategy:
220220
matrix:
221221
arch: [x86, x64]
@@ -230,7 +230,7 @@ jobs:
230230
submodules: true
231231
- name: Build ${{ env.PACKAGE_NAME }} + consumers
232232
env:
233-
AWS_CMAKE_TOOLSET: v140
233+
AWS_CMAKE_TOOLSET: v143 #Visual Studio C++ v143 is Visual Studio 2022 and msvc 17
234234
run: |
235235
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
236236
python builder.pyz build -p ${{ env.PACKAGE_NAME }} downstream
@@ -409,7 +409,7 @@ jobs:
409409
./builder localhost-test -p ${{ env.PACKAGE_NAME }} --spec=downstream
410410
411411
localhost-test-win:
412-
runs-on: windows-2022 # latest
412+
runs-on: windows-2025 # latest
413413
steps:
414414
- uses: aws-actions/configure-aws-credentials@v4
415415
with:

src/test/java/software/amazon/awssdk/crt/test/Http2RequestResponseTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,22 @@ public TestHttpResponse testHttp2Request(String method, String endpoint, String
9292

9393
Assert.assertNotEquals(-1, response.blockType);
9494

95-
boolean hasContentLengthHeader = false;
9695

9796
/* The first header of response has to be ":status" for HTTP/2 response */
9897
response.headers.get(0).getName().equals(":status");
99-
for (HttpHeader h : response.headers) {
100-
if (h.getName().equals("content-length")) {
101-
hasContentLengthHeader = true;
102-
}
103-
}
10498

105-
Assert.assertTrue(hasContentLengthHeader);
10699
if (response.statusCode < 500) { // if the server errored, not our fault
107100
Assert.assertEquals("Expected and Actual Status Codes don't match", expectedStatus, response.statusCode);
108101
}
102+
if (response.statusCode == 200) {
103+
boolean hasContentLengthHeader = false;
104+
for (HttpHeader h : response.headers) {
105+
if (h.getName().equals("content-length")) {
106+
hasContentLengthHeader = true;
107+
}
108+
}
109+
Assert.assertTrue("Expected to have content-length header that is missing.", hasContentLengthHeader);
110+
}
109111

110112
return response;
111113
}

src/test/java/software/amazon/awssdk/crt/test/HttpRequestResponseTest.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,19 @@ public boolean resetPosition() {
9090

9191
Assert.assertNotEquals(-1, response.blockType);
9292

93-
boolean hasContentLengthHeader = false;
9493

95-
for (HttpHeader h : response.headers) {
96-
if (h.getName().equals("Content-Length")) {
97-
hasContentLengthHeader = true;
98-
}
99-
}
100-
101-
Assert.assertTrue(hasContentLengthHeader);
10294
if (response.statusCode < 500) { // if the server errored, not our fault
10395
Assert.assertEquals("Expected and Actual Status Codes don't match", expectedStatus, response.statusCode);
10496
}
97+
if (response.statusCode == 200) {
98+
boolean hasContentLengthHeader = false;
99+
for (HttpHeader h : response.headers) {
100+
if (h.getName().toLowerCase().equals("content-length")) {
101+
hasContentLengthHeader = true;
102+
}
103+
}
104+
Assert.assertTrue("Expected to have content-length header that is missing.", hasContentLengthHeader);
105+
}
105106

106107
return response;
107108
}
@@ -211,18 +212,29 @@ private void testHttpUpload(boolean chunked) throws Exception {
211212
*
212213
*/
213214

215+
// The response is a JSON object, extract the "data" field using proper JSON parsing
214216
String echoedBody = null;
215-
for (String line : body.split("\n")) {
216-
String[] keyAndValue = line.split(":", 2);
217217

218-
// Found JSON Key/Value Pair
219-
if (keyAndValue.length == 2) {
220-
String key = extractValueFromJson(keyAndValue[0]);
221-
String val = extractValueFromJson(keyAndValue[1]);
218+
// Find the "data" field in the JSON response
219+
int dataIndex = body.indexOf("\"data\"");
220+
if (dataIndex != -1) {
221+
// Find the colon after "data"
222+
int colonIndex = body.indexOf(':', dataIndex);
223+
if (colonIndex != -1) {
224+
// Find the value after the colon, which should be a quoted string
225+
int valueStartIndex = body.indexOf('"', colonIndex);
226+
if (valueStartIndex != -1) {
227+
// Find the end of the quoted string
228+
int valueEndIndex = body.indexOf('"', valueStartIndex + 1);
229+
while (valueEndIndex > 0 && body.charAt(valueEndIndex - 1) == '\\') {
230+
// This quote is escaped, find the next one
231+
valueEndIndex = body.indexOf('"', valueEndIndex + 1);
232+
}
222233

223-
// Found Echoed Body
224-
if (key.equals("data")) {
225-
echoedBody = extractValueFromJson(val);
234+
if (valueEndIndex != -1) {
235+
// Extract the value between the quotes
236+
echoedBody = body.substring(valueStartIndex + 1, valueEndIndex);
237+
}
226238
}
227239
}
228240
}

0 commit comments

Comments
 (0)