Skip to content

Commit

Permalink
Issue #6973 - Setup Request/Response objects for success with Request…
Browse files Browse the repository at this point in the history
…Log (#7183)

* Issue #6973 - Setup Request/Response objects for success with RequestLog

+ Prevents reading of Request body parameters
+ Still allows raw Request.getInputStream() and
  Request.getReader() usage
+ Restores committed response status code.
+ Does not rest committed response headers.
+ Adding testcase for post-commit response header
  issue. (currently disabled)
+ Remove Request.onRequestLog()
+ Move requestlog calling from HttpChannel to Request.onCompleted
+ address scenario where HttpChannel is null

Signed-off-by: Joakim Erdfelt <[email protected]>
  • Loading branch information
joakime authored Dec 29, 2021
1 parent 95804b8 commit 3c02a03
Show file tree
Hide file tree
Showing 4 changed files with 422 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,6 @@ public void onCompleted()
if (LOG.isDebugEnabled())
LOG.debug("onCompleted for {} written={}", getRequest().getRequestURI(), getBytesWritten());

if (_requestLog != null)
_requestLog.log(_request, _response);

long idleTO = _configuration.getIdleTimeout();
if (idleTO >= 0 && getIdleTimeout() != _oldIdleTimeout)
setIdleTimeout(_oldIdleTimeout);
Expand Down
23 changes: 23 additions & 0 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,29 @@ public String changeSessionId()
*/
public void onCompleted()
{
HttpChannel httpChannel = getHttpChannel();
// httpChannel can be null in some scenarios
// it's not possible to use requestlog in those scenarios anyway.
if (httpChannel != null)
{
RequestLog requestLog = httpChannel.getRequestLog();
if (requestLog != null)
{
// Don't allow pulling more parameters
_contentParamsExtracted = true;

// Reset the status code to what was committed
MetaData.Response committedResponse = getResponse().getCommittedMetaData();
if (committedResponse != null)
{
getResponse().setStatus(committedResponse.getStatus());
// TODO: Reset the response headers to what they were when committed
}

requestLog.log(this, getResponse());
}
}

if (_sessions != null)
{
for (Session s:_sessions)
Expand Down
Loading

0 comments on commit 3c02a03

Please sign in to comment.