-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BREAKING]: Change internal layers stack to be value-based instead of…
… type-based (#789) Overhaul internal client-side "layers" to a more functional approach to simplify the interface for custom layers, refactor expected arguments to layers, and clarify abilities to modify the client-side stack: a more advanced option via pushlayer!/poplayer! to affect the global stack, and a more recommended @client macro to generate your own client that includes custom layers.
- Loading branch information
Showing
34 changed files
with
635 additions
and
1,393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,27 @@ | ||
module BasicAuthRequest | ||
|
||
using ..Base64 | ||
|
||
import ..Layer, ..request | ||
using URIs | ||
using ..Pairs: getkv, setkv | ||
import ..Messages: setheader, hasheader | ||
import ..@debug, ..DEBUG_LEVEL | ||
|
||
export basicauthlayer | ||
""" | ||
request(BasicAuthLayer, method, ::URI, headers, body) -> HTTP.Response | ||
basicauthlayer(req) -> HTTP.Response | ||
Add `Authorization: Basic` header using credentials from url userinfo. | ||
""" | ||
abstract type BasicAuthLayer{Next <: Layer} <: Layer{Next} end | ||
export BasicAuthLayer | ||
|
||
function request(::Type{BasicAuthLayer{Next}}, | ||
method::String, url::URI, headers, body; kw...) where Next | ||
|
||
userinfo = unescapeuri(url.userinfo) | ||
|
||
if !isempty(userinfo) && getkv(headers, "Authorization", "") == "" | ||
@debug 1 "Adding Authorization: Basic header." | ||
setkv(headers, "Authorization", "Basic $(base64encode(userinfo))") | ||
function basicauthlayer(handler) | ||
return function(req; basicauth::Bool=true, kw...) | ||
if basicauth | ||
userinfo = unescapeuri(req.url.userinfo) | ||
if !isempty(userinfo) && !hasheader(req.headers, "Authorization") | ||
@debug 1 "Adding Authorization: Basic header." | ||
setheader(req.headers, "Authorization" => "Basic $(base64encode(userinfo))") | ||
end | ||
end | ||
return handler(req; kw...) | ||
end | ||
|
||
return request(Next, method, url, headers, body; kw...) | ||
end | ||
|
||
|
||
end # module BasicAuthRequest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.