001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.http; 018 019/** 020 * Optional operator-supplied transform applied to request/response body text before it is written to a REST debug log. 021 * 022 * <p> 023 * This SPI is <b>not</b> a default protection. Body dumping is off by default and is enabled only by the 024 * {@code JUNEAU_REST_DEBUG_ALLOW_DUMP_BODIES} environment-variable master gate. A scrubber only ever runs once that gate 025 * has already permitted dumping; it merely chooses <i>scrubbed-vs-raw</i> body text (e.g. mask fields, drop sections). A 026 * configured scrubber never causes body content to be emitted while the gate is unset. 027 * 028 * <p> 029 * The scrubber is <b>fail-closed</b>: if {@link #scrub(String, String)} throws or returns <jk>null</jk>, the formatter 030 * emits a suppression placeholder instead of the body — it never falls back to the raw, unscrubbed body. A non-<jk>null</jk> 031 * result is still sanitized (control characters escaped) and length-capped before it reaches the log line. 032 * 033 * <p> 034 * Implementations must be <b>thread-safe</b> — the formatter may invoke {@link #scrub(String, String)} concurrently. 035 * 036 * <h5 class='section'>See Also:</h5><ul> 037 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerLoggingAndDebugging">Logging / Debugging</a> 038 * </ul> 039 * 040 * @since 10.0.0 041 */ 042public interface RestDebugBodyScrubber { 043 044 /** 045 * Transforms body text before it is logged. 046 * 047 * @param contentType The body's content type (may be <jk>null</jk> if unknown). 048 * @param body The raw (already byte-capped) body text. 049 * @return The scrubbed body text to log, or <jk>null</jk> to fail closed (the formatter emits a placeholder instead). 050 */ 051 String scrub(String contentType, String body); 052}