Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Customising HTTP requests

Source:vignettes/custom-http.Rmd
custom-http.Rmd
library(rsconnect)

Depending on the configuration of your environment, you may need tocutomize the way that rsconnect sends http requests. Typically, this isrequired for some special

.rsconnect_profile

When deploying content from the RStudio IDE, the rsconnect package’sdeployment methods are executed in a vanilla R session that doesn’texecute startup scripts. This can make it challenging to ensure optionsare set properly prior to push-button deployment, so the rsconnectpackage has a parallel set of “startup” scripts it runs prior todeploying.

The following are run in order, if they exist, prior todeployment:

  • $R_HOME/etc/rsconnect.site: LikeRprofile.site for site-wide pre-flight and options. This istypically used by system administrators.

  • ~/.rsconnect_profile, like.Rprofile;this will affect all apps that you deploy.

  • .rsconnect_profile, like.Rprofile;this will affect the current app. Unlike.Rprofile, if~/.rsconnect_profile, is present, it will also berun.

HTTP Proxy Environment Variable

The most straightforward way to specify a proxy is to set theHTTPS_PROXY environment variable. For example, you couldadd the following code to your.rsconnect_profile:

Sys.setenv(https_proxy="https://proxy.example.com")

Proxy settings can include a host-name, port, and username/passwordif necessary. The following are all valid values for thehttp_proxy environment variable:

  • http://proxy.example.com/
  • http://proxy.example.com:1080/
  • http://username:password@proxy.example.com:1080/

Custom headers and cookies

If you need to supply additional headers or cookies, you can use theoptionsrsconnect.http.headers andrsconnect.http.cookies respectively.rsconnect.http.headers needs a named vector of header namesand values:

options(  rsconnect.http.headers=c("CustomHeader1"="CustomValue","CustomHeader2"="CustomValue2"))

Whilersconnect.http.cookies expects cookies formattedthe same way that a webserver expects them:

options(  rsconnect.http.headers=c("cookie1=value1","cookie2=value2"))

And you can supply other cookie parameters if needed:

options(  rsconnect.http.headers="cookie1=value1; Expires=Thu, 31 Oct 2021 07:28:00 GMT; Secure")

The custom headers are set first, so will be overridden by theheaders that rsconnect needs to correctly operate. Similarly, cookieswill be set prior to the first request, and will be overriden byanything returned by the server.

Other custom options

Finally, you can supply any additional options supported bycurl::curl_options() withrsconnect.libcurl.options, e.g.

options(rsconnect.libcurl.options =list(proxy ="http://proxy.example.com")

Runcurl::curl_options() to see a list of options.


[8]ページ先頭

©2009-2025 Movatter.jp