Search code examples
razure-storagehttr

How to provide multiple config values to httr::GET config argument


For Azure Blob storage I need to provide authentication values, plus an additional header called x-ms-date.

Setup

library(httr)
container<-"https://preconstuff.blob.core.windows.net/?comp=list"
sak<-"Q8HvUVJLBJK+wkrIEG6LlsfFo19iDjneTwJxX/KXSnUCtTjgyyhYnH/5azeqa1bluGD94EcPcSRyBy2W2A/fHQ=="
login<-authenticate(user = "preconstuff",password = sak)
extras<-add_headers(`x-ms-date`=Sys.time())

Problem

If I run content(GET(container,config = login )) it says the date header isn't provided.

In terms of using the objects login and extras together, putting them as a list doesn't seem to work.

If I change extras to include the authentication component (taking the userpwd header construction from the authenticate function)

extras<-add_headers(httpauth =1, userpwd = paste0("preconstuff:", sak), 
                    `x-ms-date`=as.character(Sys.time()))

Then run content(GET(container,config = extras )), I get "ResourceNotFound" suggesting it's not recognising my credentials.

How to correctly pass the multiple values in?


Solution

  • All unnamed parameters passed to GET() are passed through to config. This means you you can do

    content( GET(container, login, extras) )
    

    Alternatively, he config options are basically just lists, you can use c() to combine bits. For example

    content( GET(container, config = c(login, extras)) )