setWhiteList: Set white list

Description Usage Arguments Value See Also Examples

Description

Sets a list of URL patterns to whitelist

Usage

1
setWhiteList(proxy, regex, statusCode, ...)

Arguments

proxy

An object of class "proxy". A proxy object see proxy.

regex

a character vector of regular expressions

statusCode

the HTTP status code to return for URLs that do not match the whitelist

...

Additonal function arguments

Value

invisible(proxy): An object of class "proxy" is invisibly returned. A proxy object see proxy. This allows for chaining from this function to other functions that take such an object as an argument. See examples for further details.

See Also

Other bwlist functions: addURLBlackList, clearBlackList, clearWhiteList, getBlackList, getWhiteList

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## Not run: 
  # A BMP server is assummed running on port 9090
  prxy <- proxy(bmpPort = 9090L, port = 39500L)
  library(httr)
  # use httr_proxy to configure proxy for httr
  white_list <- prxy %>% getWhiteList
  white_list
  # set an entry in the white list
  prxy %>% setWhiteList(".*r-project\\.org.*", statusCode = 333L)
  white_list <- prxy %>% getWhiteList
  white_list
  # expect passing sites
  rcran <- GET("https://cran.r-project.org/", httr_proxy(prxy))
  rproj <- GET("https://www.r-project.org/", httr_proxy(prxy))
  # expect 333 status code for non matching url
  goog <- GET("https://www.google.com/", httr_proxy(prxy))
  goog$status_code
  
  # clear the white list
  white_list <- prxy %>% 
    clearWhiteList %>% 
    getWhiteList
  length(white_list)
  
  # get the black list
  black_list <- prxy %>% getBlackList
  black_list
  
  # add site to black list
  prxy %>% addURLBlackList(".*r-project\\.org.*", statusCode = 334L)
  goog <- GET("https://www.google.com/", httr_proxy(prxy))
  
  # expect sites to return 334 status code
  rcran <- GET("https://cran.r-project.org/", httr_proxy(prxy))
  rproj <- GET("https://www.r-project.org/", httr_proxy(prxy))
  rcran$status_code
  rproj$status_code
  
  # clear black list
  black_list <- prxy %>% 
    clearBlackList %>% 
    getBlackList
  length(black_list)

  prxy %>% closeProxy

## End(Not run)

johndharrison/bmproxy documentation built on May 19, 2019, 5:13 p.m.