resInterceptor: Intercept response

Description Usage Arguments Value See Also Examples

Description

Executes the javascript against each response

Usage

1
resInterceptor(proxy, jsFilter, ...)

Arguments

proxy

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

jsFilter

Javascript response filters have access to the variables response (type io.netty.handler.codec.http.HttpResponse), contents (type net.lightbody.bmp.util.HttpMessageContents), and messageInfo (type net.lightbody.bmp.util.HttpMessageInfo). As in the request filter, messageInfo contains additional information about the message.

...

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 intercept functions: reqInterceptor

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
## Not run: 
  library(httr)
  library(xml2)
  # A BMP server is assummed running on port 9090
  prxy <- proxy(bmpPort = 9090L, port = 39500L)
  
  # filter request
  ua1 <- GET("http://httpbin.org/user-agent", httr_proxy(prxy), 
             user_agent("httr"))
  requestFilter <- "request.headers().remove('User-Agent'); 
  request.headers().add('User-Agent', 'My-Custom-User-Agent-String 1.0');"
  prxy %>% reqInterceptor(requestFilter)
  ua2 <- GET("http://httpbin.org/user-agent", httr_proxy(prxy), 
             user_agent("httr"))
  content(ua1)
  content(ua2)
  prxy %>% closeProxy
  
  #filter response
  prxy <- proxy(bmpPort = 9090L, port = 39500L)
  responseFilter <- 
    "contents.setTextContents(
      '<html><body>Response successfully intercepted</body></html>');"
  prxy %>% resInterceptor(responseFilter)
  rproj <- GET("http://r-project.org", httr_proxy(prxy)) 
  rproj %>% read_html %>% xml_find_all("//body") %>% xml_text

## End(Not run)

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