📄 rfc2616test.java
字号:
offset=checkContains(response,offset,"pathInfo=/path/R1","2. virtual host field")+1; // Virtual Host case insensitive offset=0; connector.reopen(); response=connector.getResponses("GET /path/R1 HTTP/1.1\n"+"Host: ViRtUalhOst\n"+"\n"); offset=checkContains(response,offset,"HTTP/1.1 200","2. virtual host field")+1; offset=checkContains(response,offset,"Virtual Dump","2. virtual host field")+1; offset=checkContains(response,offset,"pathInfo=/path/R1","2. virtual host field")+1; // Virtual Host offset=0; connector.reopen(); response=connector.getResponses("GET /path/R1 HTTP/1.1\n"+"\n"); offset=checkContains(response,offset,"HTTP/1.1 400","3. no host")+1; } /* --------------------------------------------------------------- */ public void test8_1() { try { String response; int offset=0; connector.reopen(); 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 OK\015\012","8.1.2 default")+10; checkContains(response,offset,"Content-Length: ","8.1.2 default"); offset=0; connector.reopen(); response=connector.getResponses("GET /R1 HTTP/1.1\n"+"Host: localhost\n"+"\n"+ "GET /R2 HTTP/1.1\n"+"Host: localhost\n"+"Connection: close\n"+"\n"+ "GET /R3 HTTP/1.1\n"+"Host: localhost\n"+"Connection: close\n"+"\n"); offset=checkContains(response,offset,"HTTP/1.1 200 OK\015\012","8.1.2 default")+1; offset=checkContains(response,offset,"/R1","8.1.2 default")+1; assertEquals("8.1.2.1 close",-1,response.indexOf("/R3")); offset=checkContains(response,offset,"HTTP/1.1 200 OK\015\012","8.1.2.2 pipeline")+11; offset=checkContains(response,offset,"Connection: close","8.1.2.2 pipeline")+1; offset=checkContains(response,offset,"/R2","8.1.2.1 close")+3; } catch (Exception e) { e.printStackTrace(); assertTrue(false); } } /* --------------------------------------------------------------- */ public void test8_2() { try { String response; int offset=0; connector.reopen(); // No Expect 100 offset=0; connector.reopen(); response=connector.getResponses("GET /R1 HTTP/1.1\n"+ "Host: localhost\n"+ "Content-Type: text/plain\n"+ "Content-Length: 8\n"+ "\n",true); assertTrue("8.2.3 no expect 100",response==null || response.length()==0); response=connector.getResponses("AbCdEf\015\012"); offset=checkContains(response,offset,"HTTP/1.1 200","8.2.3 no expect 100")+1; offset=checkContains(response,offset,"AbCdEf","8.2.3 no expect 100")+1; // Expect Failure offset=0; connector.reopen(); response=connector.getResponses("GET /R1 HTTP/1.1\n"+"Host: localhost\n"+"Expect: unknown\n"+"Content-Type: text/plain\n"+"Content-Length: 8\n" +"\n"); offset=checkContains(response,offset,"HTTP/1.1 417","8.2.3 expect failure")+1; // Expect with body offset=0; connector.reopen(); response=connector.getResponses("GET /R1 HTTP/1.1\n"+"Host: localhost\n"+"Expect: 100-continue\n"+"Content-Type: text/plain\n" +"Content-Length: 8\n"+"Connection: close\n"+"\n"+"123456\015\012"); checkNotContained(response,offset,"HTTP/1.1 100 ","8.2.3 expect 100"); offset=checkContains(response,offset,"HTTP/1.1 200 OK","8.2.3 expect with body")+1; // Expect 100 offset=0; connector.reopen(); response=connector.getResponses("GET /R1 HTTP/1.1\n"+ "Host: localhost\n"+ "Connection: close\n"+ "Expect: 100-continue\n"+ "Content-Type: text/plain\n"+ "Content-Length: 8\n"+ "\n",true); offset=checkContains(response,offset,"HTTP/1.1 100 ","8.2.3 expect 100")+1; checkNotContained(response,offset,"HTTP/1.1 200","8.2.3 expect 100"); response=connector.getResponses("654321\015\012"); offset=checkContains(response,offset,"HTTP/1.1 200","8.2.3 expect 100")+1; offset=checkContains(response,offset,"654321","8.2.3 expect 100")+1; } catch (Exception e) { e.printStackTrace(); assertTrue(false); } finally { } } /* --------------------------------------------------------------- */ public void test9_2() { // TODO /* * try { TestListener listener = new TestListener(); String response; * int offset=0; connector.reopen(); * // Default Host offset=0; connector.reopen(); * response=connector.getResponses("OPTIONS * HTTP/1.1\n"+ "Connection: * close\n"+ "Host: localhost\n"+ "\n"); * offset=checkContains(response,offset, "HTTP/1.1 200","200")+1; * offset=checkContains(response,offset, "Allow: GET, HEAD, POST, PUT, * DELETE, MOVE, OPTIONS, TRACE","Allow")+1; * } catch(Exception e) { e.printStackTrace(); assertTrue(false); } */ } /* --------------------------------------------------------------- */ public void test9_4() { try { String get=connector.getResponses("GET /R1 HTTP/1.0\n"+"Host: localhost\n"+"\n"); checkContains(get,0,"HTTP/1.1 200","GET"); checkContains(get,0,"Content-Type: text/html","GET _content"); checkContains(get,0,"<html>","GET body"); connector.reopen(); String head=connector.getResponses("HEAD /R1 HTTP/1.0\n"+"Host: localhost\n"+"\n"); checkContains(head,0,"HTTP/1.1 200","HEAD"); checkContains(head,0,"Content-Type: text/html","HEAD _content"); assertEquals("HEAD no body",-1,head.indexOf("<html>")); } catch (Exception e) { e.printStackTrace(); assertTrue(false); } } /* --------------------------------------------------------------- */ public void test9_8() { // TODO /* * try { TestListener listener = new TestListener(); String response; * int offset=0; connector.reopen(); * // Default Host offset=0; connector.reopen(); * response=connector.getResponses("TRACE /path HTTP/1.1\n"+ "Host: * localhost\n"+ "Connection: close\n"+ "\n"); * offset=checkContains(response,offset, "HTTP/1.1 200","200")+1; * offset=checkContains(response,offset, "Content-Type: message/http", * "message/http")+1; offset=checkContains(response,offset, "TRACE /path * HTTP/1.1\r\n"+ "Host: localhost\r\n", "Request"); } catch(Exception * e) { e.printStackTrace(); assertTrue(false); } */ } /* --------------------------------------------------------------- */ public void test10_2_7() { // TODO /* * * try { TestListener listener = new TestListener(); String response; * int offset=0; connector.reopen(); * // check to see if corresponging GET w/o range would return // a) * ETag // b) Content-Location // these same headers will be required * for corresponding // sub range requests * * response=connector.getResponses("GET /" + * TestRFC2616.testFiles[0].name + " HTTP/1.1\n"+ "Host: localhost\n"+ * "Connection: close\n"+ "\n"); * * boolean noRangeHasContentLocation = * (response.indexOf("\r\nContent-Location: ") != -1); * * // now try again for the same resource but this time WITH range * header * * response=connector.getResponses("GET /" + * TestRFC2616.testFiles[0].name + " HTTP/1.1\n"+ "Host: localhost\n"+ * "Connection: close\n"+ "Range: bytes=1-3\n"+ "\n"); * * offset=0; connector.reopen(); offset=checkContains(response,offset, * "HTTP/1.1 206 Partial Content\r\n", "1. proper 206 status code"); * offset=checkContains(response,offset, "Content-Type: text/plain", "2. * _content type") + 2; offset=checkContains(response,offset, * "Last-Modified: " + TestRFC2616.testFiles[0].modDate + "\r\n", "3. * correct resource mod date"); * // if GET w/o range had Content-Location, then the corresponding // * response for the a GET w/ range must also have that same header * * offset=checkContains(response,offset, "Content-Range: bytes 1-3/26", * "4. _content range") + 2; * * if (noRangeHasContentLocation) { * offset=checkContains(response,offset, "Content-Location: ", "5. * Content-Location header as with 200"); } else { // no need to check * for Conten-Location header in 206 response // spec does not require * existence or absence if these want any // header for the get w/o * range } * * String expectedData = TestRFC2616.testFiles[0].data.substring(1, * 3+1); offset=checkContains(response,offset, expectedData, "6. * subrange data: \"" + expectedData + "\""); } catch(Exception e) { * e.printStackTrace(); assertTrue(false); } * */ } /* --------------------------------------------------------------- */ public void test10_3() { // TODO /* * try { TestListener listener = new TestListener(); String response; * int offset=0; connector.reopen(); * // HTTP/1.0 offset=0; connector.reopen(); * response=connector.getResponses("GET /redirect HTTP/1.0\n"+ * "Connection: Keep-Alive\n"+ "\n" ); * offset=checkContains(response,offset, "HTTP/1.1 302","302")+1; * checkContains(response,offset, "Location: /dump", "redirected"); * checkContains(response,offset, "Connection: close", "Connection: * close"); * * // HTTP/1.1 offset=0; connector.reopen(); * response=connector.getResponses("GET /redirect HTTP/1.1\n"+ "Host: * localhost\n"+ "\n"+ "GET /redirect HTTP/1.1\n"+ "Host: localhost\n"+ * "Connection: close\n"+ "\n" ); offset=checkContains(response,offset, * "HTTP/1.1 302","302")+1; checkContains(response,offset, "Location: * /dump", "redirected"); checkContains(response,offset, * "Transfer-Encoding: chunked", "Transfer-Encoding: chunked"); * * offset=checkContains(response,offset, "HTTP/1.1 302","302")+1; * checkContains(response,offset, "Location: /dump", "redirected"); * checkContains(response,offset, "Connection: close", "closed"); * // HTTP/1.0 _content offset=0; connector.reopen(); * response=connector.getResponses("GET /redirect/_content HTTP/1.0\n"+ * "Connection: Keep-Alive\n"+ "\n"+ "GET /redirect/_content * HTTP/1.0\n"+ "\n" ); offset=checkContains(response,offset, "HTTP/1.1 * 302","302")+1; checkContains(response,offset, "Location: /dump", * "redirected"); checkContains(response,offset, "Connection: close", * "close no _content length"); * // HTTP/1.1 _content offset=0; connector.reopen(); * response=connector.getResponses("GET /redirect/_content HTTP/1.1\n"+ * "Host: localhost\n"+ "\n"+ "GET /redirect/_content HTTP/1.1\n"+ * "Host: localhost\n"+ "Connection: close\n"+ "\n" ); * offset=checkContains(response,offset, "HTTP/1.1 302","302")+1; * checkContains(response,offset, "Location: /dump", "redirected"); * checkContains(response,offset, "Transfer-Encoding: chunked", "chunked * _content length"); * * offset=checkContains(response,offset, "HTTP/1.1 302","302")+1; * checkContains(response,offset, "Location: /dump", "redirected"); * checkContains(response,offset, "Connection: close", "closed"); * } catch(Exception e) { e.printStackTrace(); assertTrue(false); } * */ } /* --------------------------------------------------------------- */ public void checkContentRange(LocalConnector listener, String tname, String path, String reqRanges, int expectedStatus, String expectedRange, String expectedData) { try { String response; int offset=0; connector.reopen(); String byteRangeHeader=""; if (reqRanges!=null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -