/**
* Sahi - Web Automation and Test Tool
*
* Copyright 2006 V Narayan Raman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.sahi.response;
import java.io.UnsupportedEncodingException;
import net.sf.sahi.ProcessCommon;
import net.sf.sahi.config.Configuration;
import net.sf.sahi.request.HttpRequest;
import net.sf.sahi.stream.filter.HTMLModifierFilter;
import net.sf.sahi.stream.filter.JSModifierFilter;
import net.sf.sahi.util.DbUtils;
/**
* User: nraman Date: May 14, 2005 Time: 1:43:05 AM
*/
public class HttpModifiedResponse2 extends HttpResponse {
boolean isSSL = false;
private String fileExtension;
private String charset;
private String dataString;
public HttpModifiedResponse2(final HttpResponse response, final boolean isSSL, String fileExtension, int responseCode) {
this.fileExtension = fileExtension;
copyFrom(response);
/*
removing cache headers again for login problem.
test on IE sahi.co.in login/logout
*/
this.isSSL = isSSL;
if (responseCode < 300 || responseCode >= 400) { // Response code other than 3xx
boolean html = isHTML();
boolean js = isJs();
boolean injectHeader = false;
if (html || js){
charset(); // set it
final byte[] data = data();
if (data == null) {
dataString = "";
} else {
try {
dataString = new String(data, charset);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
dataString = new String(data);
}
}
if (html) {
HTMLModifierFilter htmlModifierFilter = new HTMLModifierFilter(charset, isXHTML(), isSSL);
htmlModifierFilter.modifyHeaders(response);
String tempStr = dataString;
if (dataString.length() > 30) {
tempStr = dataString.substring(0,30);
}
tempStr = tempStr.replaceAll("\\s", "");
if (tempStr.startsWith("