Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TopLayer layer at the top of every stack #737

Merged
merged 4 commits into from
Aug 1, 2021
Merged

Add TopLayer layer at the top of every stack #737

merged 4 commits into from
Aug 1, 2021

Conversation

christopher-dG
Copy link
Member

This is a fix for JuliaTesting/BrokenRecord.jl#20.

BrokenRecord adds an extra default layer that is meant to go at the top of the stack, so the before layer is top_layer(stack()). Currently, that's RedirectLayer. But afterwards, if you try to create a stack with redirects disabled (AWS.jl does this), HTTP can't insert the extra layer anywhere.

This introduces a TopLayer that is always at the top of stack(), and does nothing but pass on its arguments to the next layer. That way, we can guarantee that a layer inserted before top_layer(stack()) will always be insertable.

Before:

julia> using HTTP

julia> abstract type MyLayer{Next <: HTTP.Layer} <: HTTP.Layer{Next} end

julia> HTTP.insert_default!(HTTP.top_layer(HTTP.stack()), MyLayer);

julia> HTTP.stack()
MyLayer{RedirectLayer{BasicAuthLayer{MessageLayer{RetryLayer{ExceptionLayer{ConnectionPoolLayer{StreamLayer{Union{}}}}}}}}}

julia> HTTP.stack(; redirect=false)
ERROR: HTTP.Layers.LayerNotFoundException: RedirectLayer not found in BasicAuthLayer{MessageLayer{RetryLayer{ExceptionLayer{ConnectionPoolLayer{StreamLayer{Union{}}}}}}}

Stacktrace:
  [1] insert(stack::Type{BasicAuthLayer{MessageLayer{RetryLayer{ExceptionLayer{ConnectionPoolLayer{StreamLayer{Union{}}}}}}}}, layer_before::Type{RedirectLayer}, custom_layer::Type{MyLayer})
    @ HTTP.Layers ~/Code/HTTP/src/layers.jl:110
  [2] (::HTTP.var"#24#25")(stack::Type, ::Tuple{UnionAll, UnionAll})
    @ HTTP ~/Code/HTTP/src/HTTP.jl:603
  [3] BottomRF
    @ ./reduce.jl:81 [inlined]
  [4] _foldl_impl(op::Base.BottomRF{HTTP.var"#24#25"}, init::Type, itr::Set{Tuple{Union{Type{Union{}}, UnionAll}, UnionAll}})
    @ Base ./reduce.jl:58
  [5] foldl_impl
    @ ./reduce.jl:48 [inlined]
  [6] mapfoldl_impl(f::typeof(identity), op::HTTP.var"#24#25", nt::Type, itr::Set{Tuple{Union{Type{Union{}}, UnionAll}, UnionAll}})
    @ Base ./reduce.jl:44
  [7] mapfoldl(f::Function, op::Function, itr::Set{Tuple{Union{Type{Union{}}, UnionAll}, UnionAll}}; init::Type)
    @ Base ./reduce.jl:160
  [8] #mapreduce#218
    @ ./reduce.jl:287 [inlined]
  [9] #reduce#220
    @ ./reduce.jl:456 [inlined]
 [10] stack(; redirect::Bool, aws_authorization::Bool, cookies::Bool, canonicalize_headers::Bool, retry::Bool, status_exception::Bool, readtimeout::Int64, detect_content_type::Bool, verbose::Int64, kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ HTTP ~/Code/HTTP/src/HTTP.jl:602
 [11] top-level scope
    @ REPL[5]:1

@codecov-commenter
Copy link

codecov-commenter commented Jul 31, 2021

Codecov Report

Merging #737 (04c3832) into master (ed987aa) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #737   +/-   ##
=======================================
  Coverage   76.88%   76.89%           
=======================================
  Files          37       38    +1     
  Lines        2444     2445    +1     
=======================================
+ Hits         1879     1880    +1     
  Misses        565      565           
Impacted Files Coverage Δ
src/HTTP.jl 97.82% <100.00%> (ø)
src/TopRequest.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ed987aa...04c3832. Read the comment docs.

Copy link
Member

@quinnj quinnj left a comment

Choose a reason for hiding this comment

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

LGTM

@quinnj quinnj merged commit 11bcccc into master Aug 1, 2021
@quinnj quinnj deleted the cdg/toplayer branch August 1, 2021 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants