Code with Finding: |
class JigsawHttpServletResponse {
public void addHeader(String name, String value) {
String lname = name.toLowerCase();
HeaderValue hvalue = reply.getHeaderValue(lname);
//
// Horrible, Shame on us, I hate that
//
if (hvalue == null) {
setHeader(name, value);
} else if (hvalue instanceof HttpAcceptCharsetList) {
HttpAcceptCharsetList acl = (HttpAcceptCharsetList) hvalue;
acl.addCharset(HttpFactory.parseAcceptCharset(value));
} else if (hvalue instanceof HttpAcceptEncodingList) {
HttpAcceptEncodingList ael = (HttpAcceptEncodingList) hvalue;
ael.addEncoding(HttpFactory.parseAcceptEncoding(value));
} else if (hvalue instanceof HttpAcceptLanguageList) {
HttpAcceptLanguageList all = (HttpAcceptLanguageList) hvalue;
all.addLanguage(HttpFactory.parseAcceptLanguage(value));
} else if (hvalue instanceof HttpAcceptList) {
HttpAcceptList al = (HttpAcceptList) hvalue;
al.addAccept(HttpFactory.parseAccept(value));
} else if (hvalue instanceof HttpEntityTagList) {
HttpEntityTagList etl = (HttpEntityTagList) hvalue;
etl.addTag(HttpFactory.parseETag(value));
} else if (hvalue instanceof HttpExtList) {
HttpExtList el = (HttpExtList) hvalue;
el.addHttpExt(new HttpExt(value, false));
} else if (hvalue instanceof HttpCookieList) {
// shouldn't be used, but who knows?
HttpCookieList cl = (HttpCookieList) hvalue;
HttpCookieList ncl = HttpFactory.parseCookieList(value);
HttpCookie scookies[] = ncl.getCookies();
for (int i = 0 ; i < scookies.length ; i++) {
HttpCookie cookie = scookies[i];
cl.addCookie(cookie.getName(), cookie.getValue());
}
} else if (hvalue instanceof HttpParamList) {
int idx = value.indexOf('=');
if (idx != -1) {
String pname = value.substring(0, idx);
String pvalue = value.substring(idx+1);
HttpParamList pl = (HttpParamList) hvalue;
pl.setParameter(pname, pvalue);
}
} else if (hvalue instanceof HttpRangeList) {
HttpRangeList rl = (HttpRangeList) hvalue;
rl.addRange(HttpFactory.parseRange(value));
} else if (hvalue instanceof HttpSetCookieList) {
HttpSetCookieList scl = (HttpSetCookieList) hvalue;
HttpSetCookieList nscl = HttpFactory.parseSetCookieList(value);
HttpSetCookie scookies[] = nscl.getSetCookies();
for (int i = 0 ; i < scookies.length ; i++) {
scl.addSetCookie(scookies[i]);
}
} else if (hvalue instanceof HttpTokenList) {
((HttpTokenList) hvalue).addToken(value, true);
} else if (hvalue instanceof HttpWarningList) {
HttpWarningList wl = (HttpWarningList) hvalue;
wl.addWarning(HttpFactory.parseWarning(value));
} else if (hvalue instanceof HttpString) {
// this is the default type for unkown header
// we don't know what it is, so just append
HttpString s = (HttpString) hvalue;
String string = (String) s.getValue();
s.setValue(string+", "+value);
} else {
// not compliant with HTTP/1.1, override
setHeader(name, value);
}
}
}
|