Skip to content

Commit

Permalink
Merge pull request #185 from plotly/dev
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
etpinard committed Feb 7, 2023
2 parents 965ac54 + 6804220 commit e8344fb
Show file tree
Hide file tree
Showing 17 changed files with 174 additions and 145 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ workflows:
build:
jobs:
- "test"
when: false # disable this workflow until Percy tests are functional again
20 changes: 20 additions & 0 deletions .github/workflows/jl_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Run Julia tests

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
jl_version: ["1.6", "1.8"]
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.jl_version }}
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
with:
annotate: true
26 changes: 0 additions & 26 deletions CompatHelper.yml

This file was deleted.

8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Dash"
uuid = "1b08a953-4be3-4667-9a23-3db579824955"
authors = ["Chris Parmer <chris@plotly.com>", "Alexandr Romanenko <waralex@gmail.com>"]
version = "1.1.2"
version = "1.2.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down Expand Up @@ -30,14 +30,14 @@ DashCoreComponents = "2.0.0"
DashHtmlComponents = "2.0.0"
DashTable = "5.0.0"
DataStructures = "0.17, 0.18"
HTTP = "0.8.10, 0.9"
HTTP = "1"
JSON = "0.21"
JSON3 = "1.9"
MD5 = "0.2"
PlotlyBase = "0.8.5, 0.8.6"
YAML = "0.4.7"
julia = "1.3"
Requires = "1.3"
YAML = "0.4.7"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Dash for Julia

[![Juila tests](https://github.com/plotly/Dash.jl/actions/workflows/jl_test.yml/badge.svg)](https://github.com/plotly/Dash.jl/actions/workflows/jl_test.yml)
[![CircleCI](https://circleci.com/gh/plotly/Dash.jl/tree/master.svg?style=svg)](https://circleci.com/gh/plotly/Dash.jl/tree/master)
[![GitHub](https://img.shields.io/github/license/plotly/dashR.svg?color=dark-green)](https://github.com/plotly/Dash.jl/blob/master/LICENSE)
[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/plotly/Dash.jl.svg?color=dark-green)](https://github.com/plotly/Dash.jl/graphs/contributors)
Expand Down
5 changes: 2 additions & 3 deletions src/HttpHelpers/HttpHelpers.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module HttpHelpers

export state_handler, exception_handling_handler, compress_handler, Route, Router, add_route!
export state_handler, exception_handling_handler, compress_handler, Route, Router, add_route!, handle

import HTTP, CodecZlib

include("handlers.jl")
include("router.jl")

end
end
43 changes: 32 additions & 11 deletions src/HttpHelpers/handlers.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
struct RequestHandlerFunction <: HTTP.Handler
func::Function # func(req)
end
(x::RequestHandlerFunction)(args...) = x.func(args...)

function handle(h::RequestHandlerFunction, request::HTTP.Request, args...)
h(request, args...)
end

function handle(handler::Function, request::HTTP.Request, args...)
handler(request, args)
end

function handle(h::RequestHandlerFunction, request::HTTP.Request, state, args...)
h(request, state, args...)
end

function handle(handler::Function, request::HTTP.Request, state, args...)
handler(request, state, args)
end

function state_handler(base_handler, state)
return HTTP.RequestHandlerFunction(
return RequestHandlerFunction(
function(request::HTTP.Request, args...)
response = HTTP.handle(base_handler, request, state, args...)
response = handle(base_handler, request, state, args...)
if response.status == 200
HTTP.defaultheader!(response, "Content-Type" => HTTP.sniff(response.body))
HTTP.defaultheader!(response, "Content-Length" => string(sizeof(response.body)))
Expand All @@ -11,7 +32,7 @@ function state_handler(base_handler, state)
)
end

state_handler(base_handler::Function, state) = state_handler(HTTP.RequestHandlerFunction(base_handler), state)
state_handler(base_handler::Function, state) = state_handler(RequestHandlerFunction(base_handler), state)

function check_mime(message::HTTP.Message, mime_list)
!HTTP.hasheader(message, "Content-Type") && return false
Expand All @@ -22,9 +43,9 @@ end

const default_compress_mimes = ["text/plain", "text/html", "text/css", "text/xml", "application/json", "application/javascript", "application/css"]
function compress_handler(base_handler; mime_types::Vector{String} = default_compress_mimes, compress_min_size = 500)
return HTTP.RequestHandlerFunction(
return RequestHandlerFunction(
function(request::HTTP.Request, args...)
response = HTTP.handle(base_handler, request, args...)
response = handle(base_handler, request, args...)
if response.status == 200 && sizeof(response.body) >= compress_min_size &&
occursin("gzip", HTTP.header(request, "Accept-Encoding", "")) && check_mime(response, mime_types)
HTTP.setheader(response, "Content-Encoding" => "gzip")
Expand All @@ -38,14 +59,14 @@ function compress_handler(base_handler; mime_types::Vector{String} = default_com
end

function compress_handler(base_handler::Function; mime_types::Vector{String} = default_compress_mimes, compress_min_size = 500)
return compress_handler(HTTP.RequestHandlerFunction(base_handler), mime_types = mime_types, compress_min_size = compress_min_size)
return compress_handler(RequestHandlerFunction(base_handler), mime_types = mime_types, compress_min_size = compress_min_size)
end

function exception_handling_handler(ex_handling_func, base_handler)
return HTTP.RequestHandlerFunction(
return RequestHandlerFunction(
function(request::HTTP.Request, args...)
try
return HTTP.handle(base_handler, request, args...)
return handle(base_handler, request, args...)
catch e
return ex_handling_func(e)
end
Expand All @@ -55,12 +76,12 @@ function exception_handling_handler(ex_handling_func, base_handler)
end

exception_handling_handler(ex_handling_func, base_handler::Function) =
exception_handling_handler(ex_handling_func, HTTP.RequestHandlerFunction(base_handler))
exception_handling_handler(ex_handling_func, RequestHandlerFunction(base_handler))

function request_logging_handler(base_handler; exclude = Regex[])
return HTTP.RequestHandlerFunction(
return RequestHandlerFunction(
function(request::HTTP.Request, args...)
response = HTTP.handle(base_handler, request, args...)
response = handle(base_handler, request, args...)

return response
end
Expand Down
2 changes: 1 addition & 1 deletion src/HttpHelpers/router.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ end
add_route!(handler::Function, router::Router, method, url) = add_route!(router, Route(handler, method, url))
add_route!(handler::Function, router::Router, url) = add_route!(handler, router, nothing, url)

function HTTP.handle(router::Router, request::HTTP.Request, args...)
function handle(router::Router, request::HTTP.Request, args...)
path = HTTP.URI(request.target).path
return handle(router.routes, path, request, args...)
end
2 changes: 1 addition & 1 deletion src/handler/make_handler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function make_handler(app::DashApp, registry::ResourcesRegistry; check_layout =

compile_request = HTTP.Request("GET", prefix)
HTTP.setheader(compile_request, "Accept-Encoding" => "gzip")
HTTP.handle(handler, compile_request) #For handler precompilation
handle(handler, compile_request) #For handler precompilation

get_devsetting(app, :hot_reload) && start_reload_poll(state)

Expand Down
2 changes: 1 addition & 1 deletion src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function run_server(app::DashApp,
start_server = () -> begin
handler = make_handler(app);
server = Sockets.listen(get_inetaddr(host, port))
task = @async HTTP.serve(handler, host, port; server = server, verbose = true)
task = @async HTTP.serve(handler, host, port; server = server)
return (server, task)
end

Expand Down
30 changes: 15 additions & 15 deletions test/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using Dash

handler = make_handler(app)
request = HTTP.Request("GET", "/_dash-dependencies")
resp = HTTP.handle(handler, request)
resp = Dash.HttpHelpers.handle(handler, request)
deps = JSON3.read(String(resp.body))
@test deps[1].prevent_initial_call == false
@test deps[2].prevent_initial_call == false
Expand All @@ -43,7 +43,7 @@ using Dash

handler = make_handler(app)
request = HTTP.Request("GET", "/_dash-dependencies")
resp = HTTP.handle(handler, request)
resp = Dash.HttpHelpers.handle(handler, request)
deps = JSON3.read(String(resp.body))
@test deps[1].prevent_initial_call == true
@test deps[2].prevent_initial_call == false
Expand All @@ -65,7 +65,7 @@ using Dash

handler = make_handler(app)
request = HTTP.Request("GET", "/_dash-dependencies")
resp = HTTP.handle(handler, request)
resp = Dash.HttpHelpers.handle(handler, request)
deps = JSON3.read(String(resp.body))
@test deps[1].prevent_initial_call == true
@test deps[2].prevent_initial_call == true
Expand All @@ -87,7 +87,7 @@ using Dash

handler = make_handler(app)
request = HTTP.Request("GET", "/_dash-dependencies")
resp = HTTP.handle(handler, request)
resp = Dash.HttpHelpers.handle(handler, request)
deps = JSON3.read(String(resp.body))
@test deps[1].prevent_initial_call == true
@test deps[2].prevent_initial_call == false
Expand All @@ -110,7 +110,7 @@ end

handler = make_handler(app)
request = HTTP.Request("GET", "/_dash-dependencies")
resp = HTTP.handle(handler, request)
resp = Dash.HttpHelpers.handle(handler, request)
deps = JSON3.read(String(resp.body))

@test length(deps) == 1
Expand All @@ -124,7 +124,7 @@ end
handler = Dash.make_handler(app)
test_json = """{"output":"my-div.children","changedPropIds":["my-id.value"],"inputs":[{"id":"my-id","property":"value","value":"test"}]}"""
request = HTTP.Request("POST", "/_dash-update-component", [], Vector{UInt8}(test_json))
response = HTTP.handle(handler, request)
response = Dash.HttpHelpers.handle(handler, request)
@test response.status == 200
resp_obj = JSON3.read(String(response.body))
@test in(:multi, keys(resp_obj))
Expand All @@ -149,7 +149,7 @@ end
handler = Dash.make_handler(app)
test_json = """{"output":"..my-div.children...my-div2.children..","changedPropIds":["my-id.value"],"inputs":[{"id":"my-id","property":"value","value":"test"}], "state":[{"id":"my-id","property":"type","value":"state"}]}"""
request = HTTP.Request("POST", "/_dash-update-component", [], Vector{UInt8}(test_json))
response = HTTP.handle(handler, request)
response = Dash.HttpHelpers.handle(handler, request)
@test response.status == 200
resp_obj = JSON3.read(String(response.body))
@test in(:multi, keys(resp_obj))
Expand All @@ -172,7 +172,7 @@ end
handler = Dash.make_handler(app)
test_json = """{"output":"..my-div.children..","changedPropIds":["my-id.value"],"inputs":[{"id":"my-id","property":"value","value":"test"}], "state":[{"id":"my-id","property":"type","value":"state"}]}"""
request = HTTP.Request("POST", "/_dash-update-component", [], Vector{UInt8}(test_json))
response = HTTP.handle(handler, request)
response = Dash.HttpHelpers.handle(handler, request)
@test response.status == 200
resp_obj = JSON3.read(String(response.body))
@test in(:multi, keys(resp_obj))
Expand Down Expand Up @@ -350,7 +350,7 @@ end
)
test_json = JSON3.write(request)
request = HTTP.Request("POST", "/_dash-update-component", [], Vector{UInt8}(test_json))
response = HTTP.handle(handler, request)
response = Dash.HttpHelpers.handle(handler, request)

@test response.status == 200

Expand Down Expand Up @@ -389,7 +389,7 @@ end
)
test_json = JSON3.write(request)
request = HTTP.Request("POST", "/_dash-update-component", [], Vector{UInt8}(test_json))
response = HTTP.handle(handler, request)
response = Dash.HttpHelpers.handle(handler, request)

@test response.status == 200
resp_obj = JSON3.read(String(response.body))
Expand Down Expand Up @@ -441,7 +441,7 @@ end
)
test_json = JSON3.write(request)
request = HTTP.Request("POST", "/_dash-update-component", [], Vector{UInt8}(test_json))
response = HTTP.handle(handler, request)
response = Dash.HttpHelpers.handle(handler, request)
@test response.status == 200
s = String(response.body)
resp_obj = JSON3.read(s)
Expand Down Expand Up @@ -494,7 +494,7 @@ end
)
test_json = JSON3.write(request)
request = HTTP.Request("POST", "/_dash-update-component", [], Vector{UInt8}(test_json))
response = HTTP.handle(handler, request)
response = Dash.HttpHelpers.handle(handler, request)
@test response.status == 200
resp_obj = JSON3.read(String(response.body))
@test in(:multi, keys(resp_obj))
Expand Down Expand Up @@ -597,7 +597,7 @@ end

handler = make_handler(app)
request = HTTP.Request("GET", "/_dash-dependencies")
resp = HTTP.handle(handler, request)
resp = Dash.HttpHelpers.handle(handler, request)
deps = JSON3.read(String(resp.body))

@test length(deps) == 1
Expand Down Expand Up @@ -640,7 +640,7 @@ end

handler = make_handler(app)
request = HTTP.Request("GET", "/_dash-dependencies")
resp = HTTP.handle(handler, request)
resp = Dash.HttpHelpers.handle(handler, request)
deps = JSON3.read(String(resp.body))

@test length(deps) == 1
Expand All @@ -652,7 +652,7 @@ end
@test cb.clientside_function.namespace == "_dashprivate_my-div"
@test cb.clientside_function.function_name == "children"
request = HTTP.Request("GET", "/")
resp = HTTP.handle(handler, request)
resp = Dash.HttpHelpers.handle(handler, request)
body = String(resp.body)
@test occursin("clientside[\"_dashprivate_my-div\"]", body)
@test occursin("ns[\"children\"]", body)
Expand Down
Loading

4 comments on commit e8344fb

@etpinard
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etpinard
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register branch=master

@etpinard
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register branch=maste

@etpinard
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register branch=master

Please sign in to comment.