📄 rfc2616test.java
字号:
{ byteRangeHeader="Range: "+reqRanges+"\n"; } response=connector.getResponses("GET /"+path+" HTTP/1.1\n"+"Host: localhost\n"+byteRangeHeader+"Connection: close\n"+"\n"); switch (expectedStatus) { case 200: { offset=checkContains(response,offset,"HTTP/1.1 200 OK\r\n",tname+".1. proper 200 OK status code"); break; } case 206: { offset=checkContains(response,offset,"HTTP/1.1 206 Partial Content\r\n",tname+".1. proper 206 Partial Content status code"); break; } case 416: { offset=checkContains(response,offset,"HTTP/1.1 416 Requested Range Not Satisfiable\r\n",tname +".1. proper 416 Requested Range not Satisfiable status code"); break; } } if (expectedRange!=null) { String expectedContentRange="Content-Range: bytes "+expectedRange+"\r\n"; offset=checkContains(response,offset,expectedContentRange,tname+".2. _content range "+expectedRange); } if (expectedStatus==200||expectedStatus==206) { offset=checkContains(response,offset,expectedData,tname+".3. subrange data: \""+expectedData+"\""); } } catch (Exception e) { e.printStackTrace(); assertTrue(false); } } public void test14_16() { // TODO /* * try { TestListener listener = new TestListener(); * * int id = 0; * * // // calibrate with normal request (no ranges); if this doesnt // * work, dont expect ranges to work either // * connector.checkContentRange( t, Integer.toString(id++), * TestRFC2616.testFiles[0].name, null, 200, null, * TestRFC2616.testFiles[0].data ); * * // // server should ignore all range headers which include // at * least one syntactically invalid range // String [] totallyBadRanges = { * "bytes=a-b", "bytes=-1-2", "bytes=-1-2,2-3", "bytes=-", "bytes=-1-", * "bytes=a-b,-1-1-1", "doublehalfwords=1-2", }; * * for (int i = 0; i < totallyBadRanges.length; i++) { * connector.checkContentRange( t, "BadRange"+i, * TestRFC2616.testFiles[0].name, totallyBadRanges[i], 416, null, * TestRFC2616.testFiles[0].data ); } * * // // should test for combinations of good and syntactically // * invalid ranges here, but I am not certain what the right // behavior * is abymore // // a) Range: bytes=a-b,5-8 // // b) Range: * bytes=a-b,bytes=5-8 // // c) Range: bytes=a-b // Range: bytes=5-8 // * * // // return data for valid ranges while ignoring unsatisfiable // * ranges // * * connector.checkContentRange( t, "bytes=5-8", * TestRFC2616.testFiles[0].name, "bytes=5-8", 206, "5-8/26", * TestRFC2616.testFiles[0].data.substring(5,8+1) ); * // // server should not return a 416 if at least syntactically valid * ranges // are is satisfiable // connector.checkContentRange( t, * "bytes=5-8,50-60", TestRFC2616.testFiles[0].name, "bytes=5-8,50-60", * 206, "5-8/26", TestRFC2616.testFiles[0].data.substring(5,8+1) ); * connector.checkContentRange( t, "bytes=50-60,5-8", * TestRFC2616.testFiles[0].name, "bytes=50-60,5-8", 206, "5-8/26", * TestRFC2616.testFiles[0].data.substring(5,8+1) ); * // 416 as none are satisfiable connector.checkContentRange( t, * "bytes=50-60", TestRFC2616.testFiles[0].name, "bytes=50-60", 416, * "*REMOVE_THIS/26", null ); * * } * * catch(Exception e) { e.printStackTrace(); assertTrue(false); } */ } /* --------------------------------------------------------------- */ public void test14_23() { try { String response; int offset=0; connector.reopen(); // HTTP/1.0 OK with no host offset=0; connector.reopen(); response=connector.getResponses("GET /R1 HTTP/1.0\n"+"\n"); offset=checkContains(response,offset,"HTTP/1.1 200","200")+1; offset=0; connector.reopen(); response=connector.getResponses("GET /R1 HTTP/1.1\n"+"\n"); offset=checkContains(response,offset,"HTTP/1.1 400","400")+1; offset=0; connector.reopen(); response=connector.getResponses("GET /R1 HTTP/1.1\n"+"Host: localhost\n"+"\n"); offset=checkContains(response,offset,"HTTP/1.1 200","200")+1; offset=0; connector.reopen(); response=connector.getResponses("GET /R1 HTTP/1.1\n"+"Host:\n"+"\n"); offset=checkContains(response,offset,"HTTP/1.1 200","200")+1; } catch (Exception e) { e.printStackTrace(); assertTrue(false); } } /* --------------------------------------------------------------- */ public void test14_35() { // TODO /* * try { TestListener listener = new TestListener(); * // // test various valid range specs that have not been // tested * yet // * * connector.checkContentRange( t, "bytes=0-2", * TestRFC2616.testFiles[0].name, "bytes=0-2", 206, "0-2/26", * TestRFC2616.testFiles[0].data.substring(0,2+1) ); * * connector.checkContentRange( t, "bytes=23-", * TestRFC2616.testFiles[0].name, "bytes=23-", 206, "23-25/26", * TestRFC2616.testFiles[0].data.substring(23,25+1) ); * * connector.checkContentRange( t, "bytes=23-42", * TestRFC2616.testFiles[0].name, "bytes=23-42", 206, "23-25/26", * TestRFC2616.testFiles[0].data.substring(23,25+1) ); * * connector.checkContentRange( t, "bytes=-3", * TestRFC2616.testFiles[0].name, "bytes=-3", 206, "23-25/26", * TestRFC2616.testFiles[0].data.substring(23,25+1) ); * * connector.checkContentRange( t, "bytes=23-23,-2", * TestRFC2616.testFiles[0].name, "bytes=23-23,-2", 206, "23-23/26", * TestRFC2616.testFiles[0].data.substring(23,23+1) ); * * connector.checkContentRange( t, "bytes=-1,-2,-3", * TestRFC2616.testFiles[0].name, "bytes=-1,-2,-3", 206, "25-25/26", * TestRFC2616.testFiles[0].data.substring(25,25+1) ); * } * * catch(Exception e) { e.printStackTrace(); assertTrue(false); } */} /* --------------------------------------------------------------- */ public void test14_39() { // TODO /* * try { TestListener listener = new TestListener(); String response; * int offset=0; connector.reopen(); * // Gzip accepted offset=0; connector.reopen(); * response=connector.getResponses("GET /R1?gzip HTTP/1.1\n"+ "Host: * localhost\n"+ "TE: gzip;q=0.5\n"+ "Connection: close\n"+ "\n"); * offset=checkContains(response,offset, "HTTP/1.1 200","TE: coding")+1; * offset=checkContains(response,offset, "Transfer-Encoding: gzip","TE: * coding")+1; * // Gzip not accepted offset=0; connector.reopen(); * response=connector.getResponses("GET /R1?gzip HTTP/1.1\n"+ "Host: * localhost\n"+ "TE: deflate\n"+ "Connection: close\n"+ "\n"); * offset=checkContains(response,offset, "HTTP/1.1 501","TE: coding not * accepted")+1; * } catch(Exception e) { e.printStackTrace(); assertTrue(false); } */ } /* --------------------------------------------------------------- */ public void test19_6() { try { String response; int offset=0; connector.reopen(); offset=0; connector.reopen(); response=connector.getResponses("GET /R1 HTTP/1.0\n"+"\n"); offset=checkContains(response,offset,"HTTP/1.1 200 OK\015\012","19.6.2 default close")+10; checkNotContained(response,offset,"Connection: close","19.6.2 not assumed"); offset=0; connector.reopen(); response=connector.getResponses("GET /R1 HTTP/1.0\n"+"Host: localhost\n"+"Connection: keep-alive\n"+"\n"+ "GET /R2 HTTP/1.0\n"+"Host: localhost\n"+"Connection: close\n"+"\n"+ "GET /R3 HTTP/1.0\n"+"Host: localhost\n"+"Connection: close\n"+"\n"); offset=checkContains(response,offset,"HTTP/1.1 200 OK\015\012","19.6.2 Keep-alive 1")+1; offset=checkContains(response,offset,"Connection: keep-alive","19.6.2 Keep-alive 1")+1; offset=checkContains(response,offset,"<html>","19.6.2 Keep-alive 1")+1; offset=checkContains(response,offset,"/R1","19.6.2 Keep-alive 1")+1; offset=checkContains(response,offset,"HTTP/1.1 200 OK\015\012","19.6.2 Keep-alive 2")+11; offset=checkContains(response,offset,"Connection: close","19.6.2 Keep-alive close")+1; offset=checkContains(response,offset,"/R2","19.6.2 Keep-alive close")+3; assertEquals("19.6.2 closed",-1,response.indexOf("/R3")); offset=0; connector.reopen(); response=connector.getResponses("GET /R1 HTTP/1.0\n"+"Host: localhost\n"+"Connection: keep-alive\n"+"Content-Length: 10\n"+"\n"+"1234567890\n"+ "GET /RA HTTP/1.0\n"+"Host: localhost\n"+"Connection: keep-alive\n"+"Content-Length: 10\n"+"\n"+"ABCDEFGHIJ\n"+ "GET /R2 HTTP/1.0\n"+"Host: localhost\n"+"Connection: close\n"+"\n"+ "GET /R3 HTTP/1.0\n"+"Host: localhost\n"+"Connection: close\n"+"\n"); offset=checkContains(response,offset,"HTTP/1.1 200 OK\015\012","19.6.2 Keep-alive 1")+1; offset=checkContains(response,offset,"Connection: keep-alive","19.6.2 Keep-alive 1")+1; offset=checkContains(response,offset,"<html>","19.6.2 Keep-alive 1")+1; offset=checkContains(response,offset,"1234567890","19.6.2 Keep-alive 1")+1; offset=checkContains(response,offset,"HTTP/1.1 200 OK\015\012","19.6.2 Keep-alive 1")+1; offset=checkContains(response,offset,"Connection: keep-alive","19.6.2 Keep-alive 1")+1; offset=checkContains(response,offset,"<html>","19.6.2 Keep-alive 1")+1; offset=checkContains(response,offset,"ABCDEFGHIJ","19.6.2 Keep-alive 1")+1; offset=checkContains(response,offset,"HTTP/1.1 200 OK\015\012","19.6.2 Keep-alive 2")+11; offset=checkContains(response,offset,"Connection: close","19.6.2 Keep-alive close")+1; offset=checkContains(response,offset,"/R2","19.6.2 Keep-alive close")+3; assertEquals("19.6.2 closed",-1,response.indexOf("/R3")); } catch (Exception e) { e.printStackTrace(); assertTrue(false); } } private int checkContains(String s, int offset, String c, String test) { int o=s.indexOf(c,offset); if (o<offset) { System.err.println("FAILED: "+test); System.err.println("'"+c+"' not in:"); System.err.println(s.substring(offset)); System.err.flush(); System.out.println("--\n"+s); System.out.flush(); assertTrue(test,false); } return o; } private void checkNotContained(String s, int offset, String c, String test) { int o=s.indexOf(c,offset); assertTrue(test,o<offset); } private void checkNotContained(String s, String c, String test) { checkNotContained(s,0,c,test); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -