mirror of
https://github.com/mitb-archive/filebot
synced 2024-08-13 17:03:45 -04:00
Support for logging response content via -Dnet.filebot.web.WebRequest.log.response=true
This commit is contained in:
parent
0131bd0af5
commit
86b0776c2d
@ -81,7 +81,7 @@ public class CachedResource<K, R> implements Resource<R> {
|
||||
|
||||
try {
|
||||
ByteBuffer data = retry(() -> fetch.fetch(url, lastModified), retryLimit, retryWait);
|
||||
debug.finest(format("Received %,d bytes", data == null ? 0 : data.remaining()));
|
||||
debug.finest(WebRequest.log(data));
|
||||
|
||||
// 304 Not Modified
|
||||
if (data == null && element != null && element.getObjectValue() != null) {
|
||||
|
@ -25,6 +25,7 @@ import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
@ -53,6 +54,7 @@ import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import net.filebot.util.ByteBufferOutputStream;
|
||||
import net.filebot.util.SystemProperty;
|
||||
|
||||
public final class WebRequest {
|
||||
|
||||
@ -332,6 +334,25 @@ public final class WebRequest {
|
||||
};
|
||||
}
|
||||
|
||||
public static Supplier<String> log(ByteBuffer data) {
|
||||
return () -> {
|
||||
if (data == null) {
|
||||
return "Received 0 bytes";
|
||||
}
|
||||
|
||||
String log = String.format(Locale.ROOT, "Received %,d bytes", data.remaining());
|
||||
|
||||
// log entire response content if enabled
|
||||
SystemProperty<Boolean> response = SystemProperty.of("net.filebot.web.WebRequest.log.response", Boolean::parseBoolean, Boolean.FALSE);
|
||||
if (response.get()) {
|
||||
return log + System.lineSeparator() + UTF_8.decode(data.duplicate()) + System.lineSeparator();
|
||||
}
|
||||
|
||||
return log;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
private WebRequest() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user