Skip to content

ServiceRequest constructor doesn't accept AbstractVector #28

Description

@NHDaly

function ServiceRequest(account::String, verb::String, resource::String, data::Vector{UInt8}; headers...)
ServiceRequest(account, verb, resource, IOBuffer(data); headers...)
end

This constructor (and probably almost all functions) that takes a Vector{UInt8} should really be taking an AbstractVector{UInt8}. As it is currently defined, you will get a MethodError if you construct with e.g. codeunits("foo"):

julia> req = Azure.REST.ServiceRequest("account", "PUT", "url", codeunits("hello"))
ERROR: MethodError: no method matching Azure.REST.ServiceRequest(::String, ::String, ::String, ::Base.CodeUnits{UInt8, String})
Closest candidates are:
  Azure.REST.ServiceRequest(::String, ::String, ::String) at ~/.julia/packages/Azure/YzOHB/src/rest_api_protocol.jl:62
  Azure.REST.ServiceRequest(::String, ::String, ::String, ::Union{Nothing, IO}; headers...) at ~/.julia/packages/Azure/YzOHB/src/rest_api_protocol.jl:62
  Azure.REST.ServiceRequest(::String, ::String, ::String, ::AbstractString; headers...) at ~/.julia/packages/Azure/YzOHB/src/rest_api_protocol.jl:58
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

This is a regression from v0.3.1, where this worked correctly:

julia> req = Azure.REST.ServiceRequest("account", "PUT", "url", codeunits("hello"))
Azure.REST.ServiceRequest("account", "PUT", "url", Azure.REST.StandardHeaders(nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothin
g, nothing, nothing), Dict("x-ms-date" => "Wed, 13 Jul 2022 13:14:39 GMT", "x-ms-version" => "2016-05-31"), UInt8[0x68, 0x65, 0x6c, 0x6c, 0x6f])

julia> @which Azure.REST.ServiceRequest("account", "PUT", "url", codeunits("hello"))
Azure.REST.ServiceRequest(account::String, verb::String, resource::String, data; headers...) in Azure.REST at /Users/nathandaly/.julia/packages/Azure/ZwCcU/
src/rest_api_protocol.jl:48

note that you should be able to construct an IOBuffer this way:

julia> IOBuffer(codeunits("hello"))
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=5, maxsize=Inf, ptr=1, mark=-1)

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions