派生类java实现http代理服务

http代理  时间:2021-03-03  阅读:()

j av a实现http代理服务public void writeLog(byte[]bytes, int offset, int len,boolean browser)throws IOExc eption{for(int i=0; i len; i++)writeLog((int)bytes[offs et+i],brow s er);

//默认情况下 日志信息输出到

//标准输出设备

//派生类可以覆盖它public String processHostName(String url,String host, int port,Socket sock) {java.text.DateFormat cal=java.text.DateFormat.getDateTimeInstance();System.out.println(c al.format(new java.util.Date())+-+url+

+sock.getInetAddres s()+\nreturn host;

//执行操作的线程public void run() {

String line;

String host;int port=80;

S oc ket outbound=null;try{s ocket.s etSoTimeout(TIMEOUT);

InputStream is=s oc ket.getInputStream();

OutputStream os=null;

try{

//获取请求行的内容line=host=int state=0;boolean space;w hile(true) {int c=is.read();if(c==-1)break;if(logging)wr iteLo g(c, true);spac e=Character.isWhitespac e((char)c);sw itch(state) {case0:if(space)c ontinue;state=1;case 1:if(space) {state=2;c ontinue;

line=line+(char)c;break;case2:if(space)c ontinue; //跳过多个空白字符state=3;case3:if(space) {state=4;

//只取出主机名称部分

String host0=host;int n;n=host.indexOf( //if(n!=-1)host=host.substring(n+2);n=host.indexOf(‘/’);if(n!=-1)host=host.substring(0,n);

//分析可能存在的端口号n=host.indexOf( :if(n!=-1) {port=Integer.parseInt(host.substring(n+1));

host=host.substring(0,n);host=processHostName(host0,host,port, socket);if(p arent !=null) {hos t=parent;port=parentP ort;int retry=CONNECT_RETRI ES;while(retry-- !=0) {try{outbound=new S oc ket(host,port);break;

} catch(Exc eption e) {

//等待

Thread.s leep(CONNECT_PAUSE);if(o utb o un d==nu ll)break;outbound.s etS oT imeout(T IMEOUT);o s=outb ound.getOutput S tream();os.write(line.getBytes());os.write(‘ ‘);os.write(host0.getBytes());os.write(‘ ‘);p ip e(is,outb ound.getInputS tream(),o s,

s oc ket.getOutputS tream());break;host=host+(char)c;break;

} catch(IOException e) {

} catch(Exc eption e) {

}final ly{try{socket.close();

} catch(Exception e1) {try{outbound.c lo s e();

} catch(Exc eption e2) {void pipe(InputStream is0, InputStream is 1,OutputStream os0,OutputStream os 1) throws IOException{try{int ir;byte bytes[]=new byte[BUFSIZ];w hile(true) {try{if((ir=is 0.read(bytes))0) {os0.write(bytes,0, ir);

if(logging)wr iteLo g(byte s,0, ir, true);

} else if(ir 0)break;

} catch(InterruptedIOExc eption e) {try{if((ir=is 1.read(bytes))0) {os 1.write(bytes,0, ir);if(logging)writeLo g(byte s,0, ir, fals e);

} else if(ir 0)break;

} catch(InterruptedIOExc eption e) {

} catch(Exception e0) {

System.out.println(Pipe异常:+e0);static public void startProxy(int port,Class clobj) {ServerSocket ssock;try{ssock=new ServerSocket(port);w hile(true) {

Class[] sarg=new Class[1];

Object[] arg=new Object[1];

sarg[0]=Socket.clas s;try{java.lang.reflect.Constructor cons=clobj

.getDeclaredConstructor(sarg);arg[0]=ssock.accept();c ons.newInstanc e(arg); //创建HttpProxy或其派生类的实例} catch(Exc eption e) {

Socket esock=(Socket)arg[0];try{esock.close();

} catch(Exception ec) {

} catch(IOException e) {static public void stopProxy(){try{if(null!=HttpProxy.s oc ket)

HttpProxy.socket.close();

} catch(IOException e) {e.printStackTrac e();

//测试用的简单main方法static public void main(String args[]) {

Sys tem.out.println(在端口808启动代理服务器\n

HttpProxy.lo g=S ys tem.out;

HttpProxy.lo gging=fals e;

HttpProxy.s tartProxy(808,HttpProxy.c las s);}

来自 http://c henyu-hz.iteye.c om/b lo g/1493227

老薛主机VPS年付345元,活动进行时。

老薛主机,虽然是第一次分享这个商家的信息,但是这个商家实际上也有存在有一些年头。看到商家有在进行夏季促销,比如我们很多网友可能有需要的香港VPS主机季度及以上可以半价优惠,如果有在选择不同主机商的香港机房的可以看看老薛主机商家的香港VPS。如果没有记错的话,早年这个商家是主营个人网站虚拟主机业务的,还算不错在异常激烈的市场中生存到现在,应该算是在众多商家中早期积累到一定的用户群的,主打小众个人网站...

趣米云(18元/月)香港三网CN2云服器低至;1核1G/30G系统盘+20G数据盘/10M带宽

趣米云怎么样?趣米云是创建于2021年的国人IDC商家,虽然刚刚成立,但站长早期为3家IDC提供技术服务,已从业2年之久,目前主要从事出售香港vps、香港独立服务器、香港站群服务器等,目前在售VPS线路有三网CN2、CN2 GIA,该公司旗下产品均采用KVM虚拟化架构。由于内存资源大部分已售,而IP大量闲置,因此我们本月新增1c1g优惠套餐。点击进入:趣米云官方网站地址香港三网CN2云服务器机型活...

腾讯云CVM云服务器大硬盘方案400GB和800GB数据盘方案

最近看到群里的不少网友在搭建大数据内容网站,内容量有百万篇幅,包括图片可能有超过50GB,如果一台服务器有需要多个站点的话,那肯定默认的服务器50GB存储空间是不够用的。如果单独在购买数据盘会成本提高不少。这里我们看到腾讯云促销活动中有2款带大数据盘的套餐还是比较实惠的,一台是400GB数据盘,一台是800GB数据盘,适合他们的大数据网站。 直达链接 - 腾讯云 大数据盘套餐服务器这里我们看到当前...

http代理为你推荐
推广方法最有效的推广方法是什么?打开网页出现错误显示网页上错误,打不开网页怎么办渗透测试web渗透测试有前途吗手机区号手机号码ps抠图技巧ps抠图多种技巧,越详细越好,急~~~~~~~申请证书一、如何申请证书?申请证书求高手教下怎么申请证书怎么点亮qq空间图标怎样点亮qq空间的图标ios系统苹果手机的系统是什么?服务器连接异常手机服务器连接异常
工信部域名备案 域名备案中心 photonvps 警告本网站 丹弗 福建天翼加速 最好的qq空间 爱奇艺会员免费试用 最漂亮的qq空间 上海电信测速网站 湖南idc 卡巴斯基试用版下载 免费赚q币 时间服务器 WHMCS weblogic部署 asp简介 cc攻击 瓦工招聘 ddos攻击器 更多