fix noscript option in FileServer, add cookies option in FileServer
This commit is contained in:
parent
ec74401896
commit
1cea71d3ea
2 changed files with 30 additions and 26 deletions
|
@ -94,7 +94,9 @@ public class FileServer implements IRequestCatcher, RequestHandler.Listener {
|
|||
@Override
|
||||
public Task<BrowserContext> processBrowserContext(BrowserContext context) {
|
||||
if(data.getBoolean("noscript") != null)
|
||||
context.useJavaScript = !data.getBoolean("noscript");
|
||||
context.addJavaScript = !data.getBoolean("noscript");
|
||||
if(data.getBoolean("cookies") != null)
|
||||
context.addState = data.getBoolean("cookies");
|
||||
return IRequestCatcher.super.processBrowserContext(context);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,9 @@ public class BrowserContext {
|
|||
public final UUID uuid = UUID.randomUUID();
|
||||
public TCN data;
|
||||
private final IRequestCatcher requestCatcher;
|
||||
public boolean useJavaScript = false;
|
||||
private boolean needsChange = false;
|
||||
public boolean addState = true;
|
||||
public boolean addJavaScript = true;
|
||||
|
||||
private BrowserContext(IRequestCatcher requestCatcher) {
|
||||
this.requestCatcher = requestCatcher;
|
||||
|
@ -65,6 +66,7 @@ public class BrowserContext {
|
|||
private Task<BrowserContext> init() {
|
||||
return t((res, rej) -> {
|
||||
requestCatcher.processBrowserContext(this).err(rej).then(res).ok();
|
||||
if(addState)
|
||||
needsChange = true;
|
||||
});
|
||||
}
|
||||
|
@ -78,7 +80,7 @@ public class BrowserContext {
|
|||
public Task<Response> onSend(Response response) {
|
||||
return AsyncJSON.write(data)
|
||||
.compose((resp, res, rej) -> {
|
||||
if(response.isHTML) {
|
||||
if(addJavaScript && response.isHTML) {
|
||||
Document document = response.getHTML();
|
||||
Element element = document.createElement("script");
|
||||
Node text = document.createTextNode(
|
||||
|
@ -110,11 +112,13 @@ public class BrowserContext {
|
|||
head.appendChild(element);
|
||||
response.updateHTMLData();
|
||||
}
|
||||
if(addState) {
|
||||
if(needsChange) {
|
||||
response.cookiesToSet.put("tryumph.data", resp);
|
||||
needsChange = false;
|
||||
}
|
||||
response.cookiesToSet.put("tryumph.uuid", uuid.toString());
|
||||
}
|
||||
res.call(response);
|
||||
});
|
||||
}
|
||||
|
@ -148,14 +152,13 @@ public class BrowserContext {
|
|||
return builder.toString();
|
||||
}
|
||||
stream = new FileInputStream(file);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while((i = stream.read()) != -1) {
|
||||
builder.append((char) i);
|
||||
}
|
||||
|
||||
stream.close();
|
||||
}
|
||||
|
||||
if(!TryConfig.nocache)
|
||||
cache.put(file, builder.toString());
|
||||
|
@ -184,8 +187,6 @@ public class BrowserContext {
|
|||
return builder.toString();
|
||||
}
|
||||
stream = new FileInputStream(file);
|
||||
}
|
||||
|
||||
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
||||
|
||||
int i = 0;
|
||||
|
@ -196,6 +197,7 @@ public class BrowserContext {
|
|||
stream.close();
|
||||
s.close();
|
||||
st = new String(s.toByteArray());
|
||||
}
|
||||
if(!TryConfig.nocache)
|
||||
cache.put(file, st);
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue