Buffering
The buffering middleware limits the size of requests that can be forwarded to services.
With buffering, Traefik Hub reads the entire request into memory (possibly buffering large requests into disk), and rejects requests that are over a specified size limit.
This can help services avoid large amounts of data (multipart/form-data
for example), and can minimize the time spent sending data to a Service.
Configuration Options
maxRequestBodyBytes
Field | Description | Default | Required |
---|---|---|---|
maxRequestBodyBytes | The maxRequestBodyBytes option configures the maximum allowed body size for the request (in bytes). If the request exceeds the allowed size, it is not forwarded to the Service, and the client gets a 413 (Request Entity Too Large) response. | 0 | No |
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: limit
spec:
buffering:
maxRequestBodyBytes: 2000000
memRequestBodyBytes
Field | Description | Default | Required |
---|---|---|---|
memRequestBodyBytes | You can configure a threshold (in bytes) from which the request will be buffered on disk instead of in memory with the memRequestBodyBytes option. | 1048576 | No |
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: limit
spec:
buffering:
memRequestBodyBytes: 2000000
maxResponseBodyBytes
Field | Description | Default | Required |
---|---|---|---|
maxResponseBodyBytes | The maxResponseBodyBytes option configures the maximum allowed response size from the Service (in bytes). If the response exceeds the allowed size, it is not forwarded to the client. The client gets a 500 (Internal Server Error) response instead. | 0 | No |
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: limit
spec:
buffering:
maxResponseBodyBytes: 2000000
memResponseBodyBytes
Field | Description | Default | Required |
---|---|---|---|
memResponseBodyBytes | You can configure a threshold (in bytes) from which the response will be buffered on disk instead of in memory with the memResponseBodyBytes option. | 1048576 | No |
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: limit
spec:
buffering:
memResponseBodyBytes: 2000000
retryExpression
Field | Description | Default | Required |
---|---|---|---|
retryExpression | You can have the buffering middleware replay the request using retryExpression . | "" | No |
Retry once in the case of a network error
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: limit
spec:
buffering:
retryExpression: "IsNetworkError() && Attempts() < 2"
The retry expression is defined as a logical combination of the functions below with the operators AND (&&
) and OR (||
).
At least one function is required:
Attempts()
number of attempts (the first one counts).ResponseCode()
response code of the Service.IsNetworkError()
whether the response code is related to networking error.