1 /* Written and copyright 2001-2003 Benjamin Kohl.
\r
2 * Distributed under the GNU General Public License; see the README file.
\r
3 * This code comes with NO WARRANTY.
\r
6 import java.io.IOException;
\r
7 import java.io.InputStream;
\r
8 import java.io.BufferedInputStream;
\r
9 import java.net.InetAddress;
\r
10 import java.net.UnknownHostException;
\r
14 File: Jhttpp2BufferedFilterStream.java
\r
15 @author Benjamin Kohl
\r
17 public class Jhttpp2ClientInputStream {
\r
18 private boolean filter;
\r
20 * This is set to true with requests with bodies, like "POST"
\r
26 private void init() {
\r
30 public Jhttpp2ClientInputStream() {
\r
35 public Request read(String str, Jhttpp2HTTPSession connection, tag ct, tag tc) {
\r
36 //can check for ssl first
\r
37 String s=readstr(str, connection);
\r
39 return new Request(s){}{ct, tc};
\r
44 public Request readfirst(String str, Jhttpp2HTTPSession connection, tag ct, tag tc) {
\r
45 String s=readstr(str, connection);
\r
47 return new Request(s){first}{ct, tc};
\r
52 public String readstr(String str, Jhttpp2HTTPSession connection) {
\r
55 boolean tempssl=false;
\r
60 String buf = getLine(str); // reads the first line
\r
61 str = updateBuffer(str, buf);
\r
65 if (buf.startsWith("CONNECT"))
\r
69 buf = getLine(str); // reads the first line
\r
70 str = updateBuffer(str, buf);
\r
75 if (buf.length()<=2) {
\r
78 if (buf.toUpperCase().startsWith("CONTENT-LENGTH")) {
\r
79 String clen=buf.substring(16);
\r
80 if (clen.indexOf("\r")!=-1)
\r
81 clen=clen.substring(0,clen.indexOf("\r"));
\r
83 if(clen.indexOf("\n")!=-1) clen=clen.substring(0,clen.indexOf("\n"));
\r
84 content_len=Integer.parseInt(clen);
\r
89 buf=getAdditional(str, content_len);
\r
90 str = updateBuffer(str, buf);
\r
102 * @exception IOException
\r
104 public static String getLine(String str) {
\r
105 int l=str.indexOf('\n');
\r
107 return str.substring(0, l+1);
\r
112 public static String getAdditional(String str, int content_len) {
\r
113 if (content_len>str.length())
\r
116 return str.substring(0, content_len);
\r
120 public static String updateBuffer(String buf, String str) {
\r
122 return buf.substring(str.length(), buf.length());
\r
128 * @return boolean whether the actual connection was established with the CONNECT method.
\r
131 public boolean isTunnel() {
\r