📄 connectmethod.java
字号:
/*
* Created on Feb 25, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.maverick.http;
import java.io.IOException;
import java.io.OutputStream;
import com.maverick.ssl.SSLTransport;
/* DEBUG */import org.apache.commons.logging.*;
import java.util.Enumeration;
/**
* @author lee
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ConnectMethod extends HttpMethod {
String hostname;
int port;
boolean targetIsSecure;
HttpMethod toExecute;
/* DEBUG */static Log log = LogFactory.getLog(ConnectMethod.class);
public ConnectMethod(String hostname, int port, boolean targetIsSecure, HttpMethod toExecute) {
super("CONNECT", hostname + ":" + port);
this.hostname = hostname;
this.port = port;
this.targetIsSecure = targetIsSecure;
this.toExecute = toExecute;
}
public ConnectMethod(String hostname, int port, boolean targetIsSecure) {
this(hostname, port, targetIsSecure, null);
}
public String getURI() {
return hostname + ":" + port;
}
public void processRequest(HttpRequest request) {
request.setHeaderField("Proxy-Connection", "Keep-Alive");
}
public HttpResponse execute(HttpRequest request, HttpConnection con) throws IOException {
HttpResponse response = super.execute(request, con);
/* DEBUG */log.info("HTTP CONNECT " + hostname + ":" + port + " returned " + response.getStatus()
/* DEBUG */ + " [" + response.getReason() + "]");
/* DEBUG */for (Enumeration e = response.getHeaderFieldNames(); e.hasMoreElements(); ) {
/* DEBUG */ String name = (String) e.nextElement();
/* DEBUG */ log.info(name + ": " + response.getHeaderField(name));
/* DEBUG */}
if(response.getStatus()==200) {
if(targetIsSecure)
((SocketWithLayeredTransport)response.getConnection().getSocket()).pushTransport(new SSLTransport());
}
return response;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -