@@ -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