Log HTTP headers in debug mode

pull/17/merge
Richard Körber 2015-12-18 00:29:33 +01:00
parent e6cfc3d159
commit 97d0856a04
1 changed files with 18 additions and 0 deletions

View File

@ -91,6 +91,8 @@ public class DefaultConnection implements Connection {
conn.connect();
logHeaders();
return conn.getResponseCode();
} catch (IOException ex) {
throw new AcmeException("API access failed", ex);
@ -131,6 +133,8 @@ public class DefaultConnection implements Connection {
conn.setFixedLengthStreamingMode(outputData.length);
conn.connect();
logHeaders();
try (OutputStream out = conn.getOutputStream()) {
out.write(outputData);
}
@ -313,4 +317,18 @@ public class DefaultConnection implements Connection {
return Base64Url.decode(nonceHeader);
}
/**
* Log all HTTP headers in debug mode.
*/
private void logHeaders() {
if (LOG.isDebugEnabled()) {
Map<String, List<String>> headers = conn.getHeaderFields();
for (String key : headers.keySet()) {
for (String value : headers.get(key)) {
LOG.debug("HEADER {}: {}", key, value);
}
}
}
}
}