totally remove the bug when record script
This commit is contained in:
parent
e6526432a8
commit
accd06febb
|
@ -1,17 +1,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Bench4Q Test Case</title>
|
||||
<link href="style/bootstrap-cerulean.css" />
|
||||
<link href="style/bootstrap-classic.css" />
|
||||
<link href="style/bootstrap-cerulean.css" />
|
||||
</head>
|
||||
<body>
|
||||
<img src="images/1.jpg" alt="No this one" />
|
||||
<img src="images/2.jpg" alt="No this one" />
|
||||
<img src="images/3.jpg" alt="No this one" />
|
||||
|
||||
<script src="script/agentTable.js" type="text/javascript"></script>
|
||||
<script src="script/base.js" type="text/javascript"></script>
|
||||
</body>
|
||||
|
||||
<html><head><meta http-equiv="Content-Type" content="text/html;charset=gb2312"><title>????????????? </title><style>html{overflow-y:auto}body{font:12px arial;text-align:center;background:#fff}body,p,form,ul{margin:0;padding:0}body,form,#fm{position:relative}td{text-align:left}img{border:0}a{color:#00c}a:active{color:#f60}#u{padding:7px 10px 3px 0;text-align:right}#m{width:680px;margin:0 auto}#nv{font-size:16px;margin:0 0 4px;text-align:left;text-indent:117px}#nv a,#nv b,.btn,#lk{font-size:14px}#fm{padding-left:90px;text-align:left}#kw{width:404px;height:22px;padding:4px 7px;padding:6px 7px 2px\9;font:16px arial;background:url(http://www.baidu.com/img/i-1.0.0.png) no-repeat -304px 0;_background-attachment:fixed;border:1px solid #cdcdcd;border-color:#9a9a9a #cdcdcd #cdcdcd #9a9a9a;vertical-align:top}.btn{width:95px;height:32px;padding:0;padding-top:2px\9;border:0;background:#ddd url(http://www.baidu.com/img/i-1.0.0.png) no-repeat;cursor:pointer}.btn_h{background-position:-100px 0}#kw,.btn_wr{margin:0 5px 0 0}.btn_wr{width:97px;height:34px;display:inline-block;background:url(http://www.baidu.com/img/i-1.0.0.png) no-repeat -202px 0;_top:1px;*position:relative}#lk{margin:33px 0}#lk span{font:14px "????"}#lm{height:60px}#lh{margin:16px 0 5px;word-spacing:3px}#mCon{height:18px;line-height:18px;position:absolute;right:7px;top:8px;top:10px\9;cursor:pointer;padding:0 18px 0 0;background:url(http://www.baidu.com/img/bg-1.0.0.gif) no-repeat right -134px;background-position:right -136px\9}#mCon span{color:#00c;cursor:default;display:block}#mCon .hw{text-decoration:underline;cursor:pointer}#mMenu{width:56px;border:1px solid #9a99ff;list-style:none;position:absolute;right:7px;top:28px;display:none;background:#fff}#mMenu a{width:100%;height:100%;display:block;line-height:22px;text-indent:6px;text-decoration:none}#mMenu a:hover{background:#d9e1f6}#mMenu .ln{height:1px;background:#ccf;overflow:hidden;margin:2px;font-size:1px;line-height:1px}#cp,#cp a{color:#77c}#sh{display:none;behavior:url(#default#homepage)}</style></head>
|
||||
<body><p id="u"><a href="/gaoji/preferences.html">????????</a> | <a href="http://passport.baidu.com/?login&tpl=mn">???</a></p><div id="m"><p id="lg"><img src="http://www.baidu.com/img/baidu_sylogo1.gif" width="270" height="129" usemap="#mp"></p><p id="nv"><a href="http://news.baidu.com">?? ??</a>??<b>?? ?</b>??<a href="http://tieba.baidu.com">?? ??</a>??<a href="http://zhidao.baidu.com">? ??</a>??<a href="http://mp3.baidu.com">MP3</a>??<a href="http://image.baidu.com">? ?</a>??<a href="http://video.baidu.com">?? ?</a>??<a href="http://map.baidu.com">?? ?</a></p><div id="fm"><form name="f" action="/s"><input type="text" name="wd" id="kw" maxlength="100"><input type="hidden" name="rsv_bp" value="0"><span class="btn_wr"><input type="submit" value="??????" id="su" class="btn" onmousedown="this.className='btn btn_h'" onmouseout="this.className='btn'"></span></form><div id="mCon"><span>????</span></div><ul id="mMenu"><li><a href="#" name="ime_hw">??§Õ</a></li><li><a href="#" name="ime_py">???</a></li><li class="ln"></li><li><a href="#" name="ime_cl">???</a></li></ul></div>
|
||||
<p id="lk"><a href="http://hi.baidu.com">???</a>??<a href="http://baike.baidu.com">???</a>??<a href="http://www.hao123.com">hao123</a><span> | <a href="/more/">???>></a></span></p><p id="lm"></p><p><a id="sh" onClick="this.setHomePage('http://www.baidu.com/')" href="http://utility.baidu.com/traf/click.php?id=215&url=http://www.baidu.com" onmousedown="return ns_c({'fm':'behs','tab':'homepage','pos':0})">??????????</a></p><p id="lh"><a href="http://e.baidu.com/?refer=888">?????????</a> | <a href="http://top.baidu.com">?????????</a> | <a href="http://home.baidu.com">??????</a> | <a href="http://ir.baidu.com">About Baidu</a></p><p id="cp">©2013 Baidu <a href="/duty/">?????????</a> <a href="http://www.miibeian.gov.cn" target="_blank">??ICP?030173??</a> <img src="http://gimg.baidu.com/img/gs.gif"></p></div><map name="mp"><area shape="rect" coords="40,25,230,95" href="http://hi.baidu.com/baidu/" target="_blank" title="?????? ??????" ></map></body>
|
||||
<script>var w=window,d=document,n=navigator,k=d.f.wd,a=d.getElementById("nv").getElementsByTagName("a"),isIE=n.userAgent.indexOf("MSIE")!=-1&&!window.opera,sh=d.getElementById("sh");if(isIE&&sh&&!sh.isHomePage("http://www.baidu.com/")){sh.style.display="inline"}for(var i=0;i<a.length;i++){a[i].onclick=function(){if(k.value.length>0){var C=this,A=C.href,B=encodeURIComponent(k.value);if(A.indexOf("q=")!=-1){C.href=A.replace(/q=[^&$]*/,"q="+B)}else{this.href+="?q="+B}}}}(function(){if(/q=([^&]+)/.test(location.search)){k.value=decodeURIComponent(RegExp.$1)}})();if(n.cookieEnabled&&!/sug?=0/.test(d.cookie)){d.write('<script src=http://www.baidu.com/js/bdsug.js?v=1.0.3.0><\/script>')}function addEV(C,B,A){if(w.attachEvent){C.attachEvent("on"+B,A)}else{if(w.addEventListener){C.addEventListener(B,A,false)}}}function G(A){return d.getElementById(A)}function ns_c(E){var F=encodeURIComponent(window.document.location.href),D="",A="",B="",C=window["BD_PS_C"+(new Date()).getTime()]=new Image();for(v in E){A=E[v];D+=v+"="+A+"&"}B="&mu="+F;C.src="http://nsclick.baidu.com/v.gif?pid=201&pj=www&"+D+"path="+F+"&t="+new Date().getTime();return true}var bdimeHW={hasF:1};var imeTar="kw";var ime_t1=(new Date()).getTime();(function(){var M=G("mCon"),A=G("mMenu");var B=["????","??§Õ","???"],O=["cl","hw","py"],D=["","http://www.baidu.com/hw/hwInput_1.1.js","http://www.baidu.com/olime/bdime.js"],N=[0,0,0];var L=n.cookieEnabled;if(L&&/\bbdime=(\d)/.test(d.cookie)){H(O[RegExp.$1],false)}var K=A.getElementsByTagName("a");for(var I=0;I<K.length;I++){K[I].onclick=F}if(isIE){var E=[];var P=M.getElementsByTagName("*");for(var I=0;I<P.length;I++){E.push(P[I])}E.push(M);var P=A.getElementsByTagName("*");for(var I=0;I<P.length;I++){E.push(P[I])}E.push(A);for(var I=0;I<E.length;I++){E[I].setAttribute("unselectable","on")}}function F(){ime_t1=(new Date()).getTime();var R=this.name.split("_")[1];try{if(w.bdime){bdime.control.closeIme()}}catch(Q){}H(R,true);return false}function H(V,Q){var T=0;if(V==O[1]){T=1;M.innerHTML='<span id="imeS" class="hw">'+B[1]+"</span>";if(isIE){G("imeS").setAttribute("unselectable","on")}function S(){if(!N[1]){if(d.selection&&d.activeElement.id&&d.activeElement.id=="kw"){bdimeHW.hasF=1}bdimeHW.input=imeTar;bdimeHW.submit="su";J(D[1]);setTimeout(function(){if(typeof bdsug!="undefined"){bdsug.sug.initial()}},1000);N[1]=1}else{bdimeHW.reload(Q)}}if(Q){S()}else{addEV(G("imeS"),"click",S)}}else{if(V==O[2]){T=2;M.innerHTML="<span>"+B[2]+"</span>";if(!N[2]){J(D[2]);N[2]=1}else{try{if(w.bdime){bdime.control.openIme()}}catch(U){}}}else{M.innerHTML="<span>"+B[0]+"</span>"}}if(Q&&L){var R=new Date();R.setTime(R.getTime()+365*24*3600*1000);d.cookie="bdime="+T+";domain=baidu.com;path=/;expires="+R.toGMTString()}}function J(Q){if(Q){var R=d.createElement("script");R.src=Q;d.getElementsByTagName("head")[0].appendChild(R)}}function C(R){var R=R||window.event;var Q=R.target||R.srcElement;A.style.display=Q.id=="mCon"&&A.style.display!="block"?"block":"none"}addEV(d,"click",C)})();addEV(w,"load",function(){k.focus()});w.onunload=function(){};;</script>
|
||||
<script type="text/javascript" src="http://www.baidu.com/cache/hps/js/hps-1.1.js"></script>
|
||||
</html
|
|
@ -11,4 +11,5 @@ Accept-Language: zh-CN,zh;q=0.8
|
|||
Content-Type: multipart
|
||||
Content-Length: 100
|
||||
Pragma: No-Cache
|
||||
Cookie: BAIDUID=993724E1CAB01EE3D0C0AFAA99796E6A:FG=1; H_PS_PSSID=4381_1463_4212_4264_4451
|
||||
Cookie: BAIDUID=993724E1CAB01EE3D0C0AFAA99796E6A:FG=1; H_PS_PSSID=4381_1463_4212_4264_4451
|
||||
|
||||
|
|
|
@ -1,291 +1,135 @@
|
|||
package org.bench4q.master.scriptrecord.httpcapture;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Parses and stores a http server request. Originally posted to
|
||||
* comp.lang.java in 1996.
|
||||
*
|
||||
* @author Sherman Janes
|
||||
*/
|
||||
public class HttpRequestHeader
|
||||
{
|
||||
private static final Log log = LogFactory.getLog(HttpRequestHeader.class);
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.impl.io.DefaultHttpRequestParser;
|
||||
import org.apache.http.impl.io.HttpTransportMetricsImpl;
|
||||
import org.apache.http.impl.io.SessionInputBufferImpl;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
|
||||
/**
|
||||
* Http Request method. Such as get or post.
|
||||
*/
|
||||
public String method = new String();
|
||||
public class HttpRequestHeader {
|
||||
private static final Logger log = Logger.getLogger(HttpRequestHeader.class);
|
||||
|
||||
/**
|
||||
* The requested url. The universal resource locator that
|
||||
* hopefully uniquely describes the object or service the
|
||||
* client is requesting.
|
||||
*/
|
||||
public String url = new String();
|
||||
public String charset = new String();
|
||||
|
||||
/**
|
||||
* Version of http being used. Such as HTTP/1.0
|
||||
*/
|
||||
public String version = new String();
|
||||
public String method = new String();
|
||||
|
||||
/**
|
||||
* The client's browser's name.
|
||||
*/
|
||||
public String userAgent = new String();
|
||||
public String url = new String();
|
||||
/**
|
||||
* to support http 1.1
|
||||
*/
|
||||
public String host = new String();
|
||||
|
||||
/**
|
||||
* The requesting documents that contained the url link.
|
||||
*/
|
||||
public String referer = new String();
|
||||
public String version = new String();
|
||||
|
||||
/**
|
||||
* A internet address date of the remote copy.
|
||||
*/
|
||||
public String ifModifiedSince = new String();
|
||||
public String userAgent = new String();
|
||||
|
||||
/**
|
||||
* A list of mime types the client can accept.
|
||||
*/
|
||||
public String accept = new String();
|
||||
public String referer = new String();
|
||||
|
||||
/**
|
||||
* The clients authorization. Don't belive it.
|
||||
*/
|
||||
public String authorization = new String();
|
||||
/**
|
||||
* The type of content following the request header.
|
||||
* Normally there is no content and this is blank, however
|
||||
* the post method usually does have a content and a content
|
||||
* length.
|
||||
*/
|
||||
public String contentType = new String();
|
||||
/**
|
||||
* The length of the content following the header. Usually
|
||||
* blank.
|
||||
*/
|
||||
public int contentLength = -1;
|
||||
/**
|
||||
* The content length of a remote copy of the requested object.
|
||||
*/
|
||||
public int oldContentLength = -1;
|
||||
/**
|
||||
* Anything in the header that was unrecognized by this class.
|
||||
*/
|
||||
public String unrecognized = new String();
|
||||
/**
|
||||
* Indicates that no cached versions of the requested object are
|
||||
* to be sent. Usually used to tell proxy not to send a cached copy.
|
||||
* This may also effect servers that are front end for data bases.
|
||||
*/
|
||||
public boolean pragmaNoCache = false;
|
||||
public String ifModifiedSince = new String();
|
||||
|
||||
final static String CR = "\r\n";
|
||||
public String accept = new String();
|
||||
|
||||
/**
|
||||
* That from which we read.
|
||||
*/
|
||||
private InputStream input;
|
||||
public String authorization = new String();
|
||||
|
||||
public String contentType = new String();
|
||||
|
||||
/**
|
||||
* Parses a http header from a stream.
|
||||
*
|
||||
* @param in The stream to parse.
|
||||
*/
|
||||
public HttpRequestHeader(InputStream in) throws IOException
|
||||
{
|
||||
input = in;
|
||||
public int contentLength = -1;
|
||||
|
||||
/*
|
||||
* Read by lines
|
||||
*/
|
||||
StringTokenizer tz = new StringTokenizer(readLine());
|
||||
public int oldContentLength = -1;
|
||||
|
||||
/*
|
||||
* HTTP COMMAND LINE < <METHOD==get> <URL> <HTTP_VERSION> >
|
||||
*/
|
||||
method = getToken(tz).toUpperCase();
|
||||
url = getToken(tz);
|
||||
version = getToken(tz);
|
||||
public String unrecognized = new String();
|
||||
|
||||
while (true) {
|
||||
String line = readLine();
|
||||
log.trace(line);
|
||||
tz = new StringTokenizer(line);
|
||||
String Token = getToken(tz);
|
||||
public boolean pragmaNoCache = false;
|
||||
|
||||
// look for termination of HTTP command
|
||||
if (0 == Token.length())
|
||||
break;
|
||||
static final String CR = "\r\n";
|
||||
|
||||
if (Token.equalsIgnoreCase("USER-AGENT:")) {
|
||||
// line =<User-Agent: <Agent Description>>
|
||||
userAgent = getRemainder(tz);
|
||||
} else if (Token.equalsIgnoreCase("ACCEPT:")) {
|
||||
// line=<Accept: <Type>/<Form>
|
||||
// examp: Accept image/jpeg
|
||||
accept += " " + getRemainder(tz);
|
||||
private HttpRequest httpRequest;
|
||||
|
||||
} else if (Token.equalsIgnoreCase("REFERER:")) {
|
||||
// line =<Referer: <URL>>
|
||||
referer = getRemainder(tz);
|
||||
private HttpRequest getHttpRequest() {
|
||||
return httpRequest;
|
||||
}
|
||||
|
||||
} else if (Token.equalsIgnoreCase("PRAGMA:")) {
|
||||
// Pragma: <no-cache>
|
||||
Token = getToken(tz);
|
||||
private void setHttpRequest(HttpRequest httpRequest) {
|
||||
this.httpRequest = httpRequest;
|
||||
}
|
||||
|
||||
if (Token.equalsIgnoreCase("NO-CACHE"))
|
||||
pragmaNoCache = true;
|
||||
else
|
||||
unrecognized += "Pragma:" + Token + " "
|
||||
+ getRemainder(tz) + "\n";
|
||||
} else if (Token.equalsIgnoreCase("AUTHORIZATION:")) {
|
||||
// Authenticate: Basic UUENCODED
|
||||
authorization = getRemainder(tz);
|
||||
public HttpRequestHeader(InputStream in) throws IOException {
|
||||
SessionInputBufferImpl inputBuffer = new SessionInputBufferImpl(
|
||||
new HttpTransportMetricsImpl(), 1024);
|
||||
inputBuffer.bind(in);
|
||||
try {
|
||||
this.setHttpRequest(new DefaultHttpRequestParser(inputBuffer)
|
||||
.parse());
|
||||
|
||||
} else if (Token.equalsIgnoreCase("IF-MODIFIED-SINCE:")) {
|
||||
// line =<If-Modified-Since: <http date>
|
||||
// *** Conditional GET replaces HEAD method ***
|
||||
String str = getRemainder(tz);
|
||||
int index = str.indexOf(";");
|
||||
if (index == -1) {
|
||||
ifModifiedSince = str;
|
||||
} else {
|
||||
ifModifiedSince = str.substring(0, index);
|
||||
this.url = this.httpRequest.getRequestLine().getUri();
|
||||
this.method = this.httpRequest.getRequestLine().getMethod();
|
||||
this.version = this.httpRequest.getRequestLine()
|
||||
.getProtocolVersion().toString();
|
||||
|
||||
index = str.indexOf("=");
|
||||
if (index != -1) {
|
||||
str = str.substring(index + 1);
|
||||
oldContentLength = Integer.parseInt(str);
|
||||
}
|
||||
}
|
||||
} else if (Token.equalsIgnoreCase("CONTENT-LENGTH:")) {
|
||||
Token = getToken(tz);
|
||||
contentLength = Integer.parseInt(Token);
|
||||
} else if (Token.equalsIgnoreCase("CONTENT-TYPE:")) {
|
||||
contentType = getRemainder(tz);
|
||||
} else {
|
||||
unrecognized += Token + " " + getRemainder(tz) + CR;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.accept = this.getHeaderValue(HeaderValue.REQUEST_ACCEPT);
|
||||
this.referer = this.getHeaderValue(HeaderValue.REQUEST_REFERER);
|
||||
this.userAgent = this
|
||||
.getHeaderValue(HeaderValue.REQUEST_USER_AGENT);
|
||||
this.ifModifiedSince = this.getHeaderValue("if-modified-since");
|
||||
this.authorization = this
|
||||
.getHeaderValue(HeaderValue.REQUEST_AUTHORIZATION);
|
||||
this.contentType = this
|
||||
.getHeaderValue(HeaderValue.ENTITY_CONTENT_TYPE);
|
||||
this.pragmaNoCache = this
|
||||
.getHeaderValue(HeaderValue.GENERAL_PRAGMA)
|
||||
.equalsIgnoreCase("NO-CACHE");
|
||||
this.host = this.getHeaderValue(HeaderValue.REQUEST_HOST);
|
||||
if (this.getHttpRequest().containsHeader(
|
||||
HeaderValue.ENTITY_CONTENT_LENGHT)) {
|
||||
this.contentLength = Integer.parseInt(this.httpRequest
|
||||
.getFirstHeader(HeaderValue.ENTITY_CONTENT_LENGHT)
|
||||
.getValue());
|
||||
} else {
|
||||
this.contentLength = 0;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
} catch (HttpException e) {
|
||||
log.error(ExceptionLog.getExceptionStackTrace(e));
|
||||
} catch (NumberFormatException e) {
|
||||
log.error(ExceptionLog.getExceptionStackTrace(e));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We would like to use BufferedReader.readLine(), but it may read past
|
||||
* the header while filling its buffer. Anything it over-read would thus
|
||||
* be missed from the body. (Reading the body cannot be via a Reader-
|
||||
* derived class because we do not want to do any character set conversion
|
||||
* at this stage. It might be binary data!)
|
||||
*/
|
||||
String readLine() throws IOException
|
||||
{
|
||||
int c;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while ((c = input.read()) != '\n') {
|
||||
if (c == -1)
|
||||
throw new IOException("unterminated line in request header");
|
||||
sb.append((char) c);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
public boolean containsHeader(String name) {
|
||||
return this.getHttpRequest().containsHeader(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Rebuilds the header in a string
|
||||
* @return The header in a string.
|
||||
*/
|
||||
public String toString(boolean sendUnknowen)
|
||||
{
|
||||
String Request;
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return if contains this header return the header's value; if not return
|
||||
* ""
|
||||
*/
|
||||
public String getHeaderValue(String name) {
|
||||
if (!this.containsHeader(name)) {
|
||||
return "";
|
||||
}
|
||||
return this.getHttpRequest().getFirstHeader(name).getValue();
|
||||
}
|
||||
|
||||
if (0 == method.length())
|
||||
method = "GET";
|
||||
public String toString() {
|
||||
return toStringWithLib();
|
||||
}
|
||||
|
||||
Request = method + " " + url + " HTTP/1.0" + CR;
|
||||
public String toStringWithLib() {
|
||||
String result = this.getHttpRequest().getRequestLine().toString();
|
||||
for (Header header : this.getHttpRequest().getAllHeaders()) {
|
||||
result += CR + header.getName() + ": " + header.getValue();
|
||||
}
|
||||
result += CR + CR;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (0 < userAgent.length())
|
||||
Request += "User-Agent:" + userAgent + CR;
|
||||
|
||||
if (0 < referer.length())
|
||||
Request += "Referer:" + referer + CR;
|
||||
|
||||
if (pragmaNoCache)
|
||||
Request += "Pragma: no-cache" + CR;
|
||||
|
||||
if (0 < ifModifiedSince.length())
|
||||
Request += "If-Modified-Since: " + ifModifiedSince + CR;
|
||||
|
||||
// ACCEPT TYPES //
|
||||
if (0 < accept.length())
|
||||
Request += "Accept: " + accept + CR;
|
||||
else
|
||||
Request += "Accept: */" + "* \r\n";
|
||||
|
||||
if (0 < contentType.length())
|
||||
Request += "Content-Type: " + contentType + CR;
|
||||
|
||||
if (0 < contentLength)
|
||||
Request += "Content-Length: " + contentLength + CR;
|
||||
|
||||
|
||||
if (0 != authorization.length())
|
||||
Request += "Authorization: " + authorization + CR;
|
||||
|
||||
if (sendUnknowen) {
|
||||
if (0 != unrecognized.length())
|
||||
Request += unrecognized;
|
||||
}
|
||||
|
||||
Request += CR;
|
||||
|
||||
return Request;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* (Re)builds the header in a string.
|
||||
*
|
||||
* @return The header in a string.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return toString(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next token in a string
|
||||
*
|
||||
* @param tk String that is partially tokenized.
|
||||
* @return The remainder
|
||||
*/
|
||||
String getToken(StringTokenizer tk)
|
||||
{
|
||||
String str = "";
|
||||
if (tk.hasMoreTokens())
|
||||
str = tk.nextToken();
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the remainder of a tokenized string
|
||||
*
|
||||
* @param tk String that is partially tokenized.
|
||||
* @return The remainder
|
||||
*/
|
||||
String getRemainder(StringTokenizer tk)
|
||||
{
|
||||
String str = "";
|
||||
if (tk.hasMoreTokens())
|
||||
str = tk.nextToken();
|
||||
while (tk.hasMoreTokens()) {
|
||||
str += " " + tk.nextToken();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class RequestHandler implements Runnable {
|
|||
private ByteArrayOutputStream buffer;
|
||||
private static Object mutex = new Object();
|
||||
|
||||
RequestHandler(ProxyServer proxyServer, Socket s) {
|
||||
public RequestHandler(ProxyServer proxyServer, Socket s) {
|
||||
assert (s != null);
|
||||
this.clientSocket = s;
|
||||
this.buffer = new ByteArrayOutputStream();
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.http.HttpException;
|
||||
|
@ -59,8 +60,28 @@ public class TestHttpRequestHeader {
|
|||
@Test
|
||||
public void testToString() throws IOException {
|
||||
assertEquals(FileUtils.readFileToString(new File(PATHNAME))
|
||||
.toLowerCase(), this.getRequestHeader().toString()
|
||||
.toLowerCase(), this.getRequestHeader().toStringWithLib()
|
||||
.toLowerCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStripProxyInfoFromRequestHeader() throws Exception {
|
||||
HttpRequestHeader header = new HttpRequestHeader(new FileInputStream(
|
||||
new File(PATHNAME)));
|
||||
String res = "";
|
||||
String origUrl = "http://ir.baidu.com/phoenix.zhtml?c=188488&p=irol-homeprofile";
|
||||
|
||||
URL url = new URL(origUrl);
|
||||
header.url = url.getFile();
|
||||
res = header.toString();
|
||||
header.url = origUrl;
|
||||
System.out.println(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToStringWithLib() throws IOException {
|
||||
assertEquals(FileUtils.readFileToString(new File(PATHNAME))
|
||||
.toLowerCase(), this.getRequestHeader().toStringWithLib()
|
||||
.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue