setHeaders: Set headers

Description Usage Arguments Value See Also Examples

Description

Set and override HTTP Request headers. This sets the headers that will set by the proxy on all requests

Usage

1
setHeaders(proxy, headers = list(), ...)

Arguments

proxy

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

headers

A named list. The name of an item is the header name (such as "User-Agent") and value is a value of HTTP header to setup (such as "BrowserMob-Agent"). Example: list("User-Agent" = "BrowserMob-Agent")

...

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 overwrite functions: remapHosts, removeRewrites, rewriteURL, setAutoBAuth

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
48
49
## Not run: 
  library(httr)
  library(xml2)
  # A BMP server is assummed running on port 9090
  prxy <- proxy(bmpPort = 9090L, port = 39500L)
  prxy %>% createHAR(ref = "httr_traffic_1")
  ua1 <- GET("http://httpbin.org/user-agent", httr_proxy(prxy), 
             user_agent("httr"))
  
  prxy %>% 
    setHeaders(list("User-Agent" = "BrowserMob-Agent")) %>% 
    newPage(ref = "httr_traffic_2")
  ua2 <- GET("http://httpbin.org/user-agent", httr_proxy(prxy), 
             user_agent("httr"))
  
  prxy %>% remapHosts("www.r-project.org", "www.google.com")
  roogle <- GET("http://www.r-project.org", httr_proxy(prxy))
  roogle %>% read_html %>% xml_find_all("//a") %>% xml_attrs
  
  prxy %>% 
    newPage(ref = "httr_traffic_3")
  auth1 <-GET("http://httpbin.org/basic-auth/user/passwd", 
              httr_proxy(prxy))
  prxy %>% 
    setAutoBAuth("httpbin.org",
                 "user", "passwd")
  auth2 <-GET("http://httpbin.org/basic-auth/user/passwd", 
              httr_proxy(prxy))
  
  auth1$status_code
  auth2$status_code
  content(auth2)
  
  prxy %>% closeProxy
  
  prxy <- proxy(bmpPort = 9090L, port = 39500L)
  prxy  %>% 
    rewriteURL(match = 'http://www\\.google\\.com.*', 
               replace = 'http://www\\.r-project\\.org')
  gproj <- GET("http://www.google.com/ncr", httr_proxy(prxy))
  gproj %>% read_html %>% xml_find_all("//title") %>% xml_text

  prxy %>% removeRewrites
  gproj <- GET("http://www.google.com/ncr", httr_proxy(prxy))
  gproj %>% read_html %>% xml_find_all("//title") %>% xml_text
  
  prxy %>% closeProxy

## End(Not run)

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