8000 Bad Request Handling · Issue #103 · wookay/Bukdu.jl · GitHub
[go: up one dir, main page]

Skip to content

Bad Request Handling #103

Closed
Closed

Description

@ueliwechsler

How would I implement a 400 bad request error handling in Bukdu?
Should I overwrite the Bukdu.System.internal_error method or is there a better way.
Thanks.

Activity

  1. wookay commented on Jun 12, 2020

    @wookay
    Owner

    at first, see HTTP.jl's implementation.

    do you have any other case?

    using Bukdu
    using Test
    using Sockets
    
    port = 8080
    Bukdu.start(port)
    
    # from https://github.com/JuliaWeb/HTTP.jl/blob/master/test/server.jl
    
    # invalid HTTP
    tcp = Sockets.connect(ip"127.0.0.1", port)
    write(tcp, "GET / HTP/1.1\r\n\r\n")
    sleep(0.1)
    @test occursin(r"HTTP/1.1 400 Bad Request", String(readavailable(tcp)))
    
    # no URL
    tcp = Sockets.connect(ip"127.0.0.1", port)
    write(tcp, "SOMEMETHOD HTTP/1.1\r\nContent-Length: 0\r\n\r\n")
    sleep(0.1)
    r = String(readavailable(tcp))
    @test occursin(r"HTTP/1.1 400 Bad Request", r)
    
    Bukdu.stop()
  2. ueliwechsler commented on Jun 15, 2020

    @ueliwechsler
    ContributorAuthor

    Thanks for your detailed response.

    I am not sure, but I think my case is not covered.
    In my application, I receive a lot of huge JSONs via Post request. I would like to check the content of the request if it contains the correct keys and return a Bad Request Message if the keys does not exist.

  3. wookay commented on Jun 15, 2020

    @wookay
    Owner

    then you could set the response.status. make a function or plug.

    function check_the_content(c::YourController)
        # if the keys does not exist
        c.conn.request.response.status = 400
    end
  4. ueliwechsler commented on Jun 18, 2020

    @ueliwechsler
    ContributorAuthor

    Thank you, this works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0