Class ImageSizeLimitInterceptor
-
- All Implemented Interfaces:
-
okhttp3.Interceptor
public final class ImageSizeLimitInterceptor implements InterceptorAn OkHttp interceptor that checks if the size of an image response exceeds a specified limit.
This interceptor is designed to be used with OkHttp to prevent the loading of excessively large images, which can lead to out-of-memory errors or performance issues. It intercepts the response and checks the
contentLengthof the response body. If the content length exceeds themaxSizeBytes, it closes the response and throws a LargeImageSizeException.
-
-
Constructor Summary
Constructors Constructor Description ImageSizeLimitInterceptor(Long maxSizeBytes)
-
Method Summary
Modifier and Type Method Description Responseintercept(Interceptor.Chain chain)Intercepts the response and checks if the image size exceeds the limit. -
-
Constructor Detail
-
ImageSizeLimitInterceptor
ImageSizeLimitInterceptor(Long maxSizeBytes)
-
-
Method Detail
-
intercept
Response intercept(Interceptor.Chain chain)
Intercepts the response and checks if the image size exceeds the limit.
This method is called by OkHttp for each response. It retrieves the
contentLengthfrom the response body and compares it to themaxSizeBytes. If the content length is greater than the maximum allowed size, it closes the response and throws a LargeImageSizeException. Otherwise, it returns the original response.
-
-
-
-