Uploaded image for project: 'Apache Fineract'
  1. Apache Fineract
  2. FINERACT-426

Filter to optionally compress response with gzip

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 1.3.0
    • None

    Description

      Accept a query parameter like isCompressionRequired. If this query param is present, compress the response using gzip. This will ensure less bandwidth usage if field apps are using mobile data.

      Sample Code for response filter :-

      Inside filter method :-

      if (request.getRequestHeaders().getFirst(HttpHeaders.ACCEPT_ENCODING).contains("gzip"))

      { response.getHttpHeaders().add(HttpHeaders.CONTENT_ENCODING, "gzip"); response.setContainerResponseWriter( new Adapter(response.getContainerResponseWriter())); }

      private static final class Adapter implements ContainerResponseWriter {
      private final ContainerResponseWriter crw;

      private GZIPOutputStream gos;

      Adapter(ContainerResponseWriter crw)

      { this.crw = crw; }

      public OutputStream writeStatusAndHeaders(long contentLength, ContainerResponse response) throws IOException

      { gos = new GZIPOutputStream(crw.writeStatusAndHeaders(-1, response)); return gos; }

      public void finish() throws IOException

      { gos.finish(); crw.finish(); }

      }

      Attachments

        Issue Links

          Activity

            People

              avikg Avik Ganguly
              avikganguly010 Avik Ganguly
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: