diff --git a/src/lavinmq/http/constants.cr b/src/lavinmq/http/constants.cr index d3ccfafef8..66b11ffa5b 100644 --- a/src/lavinmq/http/constants.cr +++ b/src/lavinmq/http/constants.cr @@ -1,5 +1,6 @@ module LavinMQ module HTTP INTERNAL_UNIX_SOCKET = "/tmp/lavinmqctl.sock" + MAX_PAGE_SIZE = 10_000 end end diff --git a/src/lavinmq/http/controller.cr b/src/lavinmq/http/controller.cr index 76b47c5004..f957649261 100644 --- a/src/lavinmq/http/controller.cr +++ b/src/lavinmq/http/controller.cr @@ -32,15 +32,13 @@ module LavinMQ value[:name]? || value["name"]? end - MAX_PAGE_SIZE = 10_000 - private def page(context, iterator : Iterator(SortableJSON)) params = context.request.query_params page = params["page"]?.try(&.to_i) || 1 page_size = params["page_size"]?.try(&.to_i) || 100 if page_size > MAX_PAGE_SIZE context.response.status_code = 413 - {error: "payload_too_large", reason: "Max allowed page_size 10000"}.to_json(context.response) + {error: "payload_too_large", reason: "Max allowed page_size #{MAX_PAGE_SIZE}"}.to_json(context.response) return context end iterator = iterator.map do |i| diff --git a/src/lavinmqctl.cr b/src/lavinmqctl.cr index 584efc7b7a..731c05161a 100644 --- a/src/lavinmqctl.cr +++ b/src/lavinmqctl.cr @@ -306,10 +306,8 @@ class LavinMQCtl URI.encode_www_form(@options["vhost"]) end - MAX_PAGE_SIZE = 10_000 - - private def get(url, page = 1, items = [] of JSON::Any) - resp = http.get("#{url}?page=#{page}&page_size=#{MAX_PAGE_SIZE}", @headers) + private def get(url, page = 1, items = Array(JSON::Any).new) + resp = http.get("#{url}?page=#{page}&page_size=#{LavinMQ::HTTP::MAX_PAGE_SIZE}", @headers) handle_response(resp, 200) if data = JSON.parse(resp.body).as_h? items += data["items"].as_a