wisp icon indicating copy to clipboard operation
wisp copied to clipboard

wisp.set_max_files_size doesn't seem to restrict uploaded file size

Open praveenray opened this issue 11 months ago • 1 comments

wisp.set_max_files_size(r, 1024*1024) doesn't seem to restrict uploaded file size(s).

Test Code:

import gleam/string
import gleam/int
import gleam/list
import wisp.{type Request, type Response}
import wisp/wisp_mist
import mist
import gleam/erlang/process
import simplifile as sfile

pub fn main() {
  wisp.configure_logger()
  let assert Ok(_) = wisp_mist.handler(handler, wisp.random_string(64))
  |> mist.new()
  |> mist.port(1234)
  |> mist.start_http()

  process.sleep_forever()
}

fn handler(r: Request) -> Response {
  use  <- wisp.log_request(r)
  let r = wisp.set_max_files_size(r, 1024*1024) // this doesn't produce 413 for large files as documented.
  use form <- wisp.require_form(r)
  let sizes = list.map(form.files, fn(pair) {
    let #(_name, file) = pair
     case sfile.file_info(file.path) {
       Ok(fi) -> file.file_name <> ":" <> int.to_string(fi.size)
       _ -> "NA"
     }
  })

  wisp.ok() |> wisp.string_body(string.join(sizes, ","))
}

To Test:

curl -v -F name=file -F [email protected] "http://localhost:1234/"

praveenray avatar Jan 02 '25 17:01 praveenray

Oh no! Sorry about that

lpil avatar Jan 08 '25 12:01 lpil