Capture HTTP Response Body

Introduction

When you need to see the content of the HTTP response body while troubleshooting a problem, you can output the response body to the access log.

This action records the response body in the Nginx variable of response_body for use in the access log.

  • Maximum response body size: the maximum size of the captured response body, starting from the first byte of the response, the result is stored in the response_body variable. Unit: bytes.

Note: Because capturing the HTTP response body not only introduces unnecessary CPU overhead but also consumes a lot of additional memory and generates a lot of disk-write events. Therefore, enabling this feature will affect the overall performance of the gateway and the response speed of requests, which has a direct impact on the user experience. Therefore, when you turn on this feature, you should filter the target requests exactly as needed instead of matching all requests, and turn off the action of capturing the HTTP response body when not using this feature

Example

First, add a new log format to the Global Config - General - Log - Access Log Formats. We name the new format req-resp-body.

$request_time $remote_addr $http_host "$request-body" "$response-body"

Next, select the newly added access log format in Applications - Your App - Settings - Access Log.

Finally, we add the capture action, setting the maximum body size of the captured response body to 4096 bytes.

At this point, all configurations are complete, so let’s release the configuration.