limitBandwidth: Limit Bandwidth

Description Usage Arguments Value See Also Examples

Description

Limit the bandwidth through the proxy on the port associated with proxy argument.

Usage

1
2
limitBandwidth(proxy, downK = NULL, upK = NULL, downMaxK = NULL,
  upMaxK = NULL, latency = NULL, ...)

Arguments

proxy

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

downK

Sets the downstream bandwidth limit in kbps. Optional if NULL (default) unlimited. From the perspective of the server.

upK

Sets the upstream bandwidth limit kbps. Optional if NULL (default) unlimited. From the perspective of the server.

downMaxK

Specifies how many kilobytes in total the client is allowed to download through the proxy. Optional if NULL (default) unlimited. From the perspective of the server.

upMaxK

Specifies how many kilobytes in total the client is allowed to upload through the proxy. Optional if NULL (default) unlimited. From the perspective of the server.

latency

Add the given latency to each HTTP request. Optional, by default all requests are invoked without latency.

...

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 bandwidth functions: getBWremaining

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
50
51
52
53
54
55
56
## Not run: 
  library(httr)
  # A BMP server is assummed running on port 9090
  prxy <- proxy(bmpPort = 9090L, port = 39500L)
  tmp <- tempfile(fileext = ".dat")
  prxy %>% createHAR(ref = "httr_download_1")
  
  # http://ping.online.net/1Mo.dat a 1mb test file
  # limit bandwidth to 50kps
  prxy %>% limitBandwidth(upK = 200L)
  testDL1 <- GET("http://ping.online.net/1Mo.dat", httr_proxy(prxy), 
               httr::write_disk(tmp, overwrite = TRUE), 
               config(fresh_connect = 1L))
  
  bwDL1 <- prxy %>% getBWremaining()
  # create new page
  prxy %>% newPage(ref = "httr_download_2")
  prxy %>% limitBandwidth(upK = 100L)
  
  # empty the DNS cache
  prxy %>% emptyDNS
  testDL2 <- GET("http://ping.online.net/1Mo.dat", httr_proxy(prxy), 
                httr::write_disk(tmp, overwrite = TRUE), 
                config(fresh_connect = 1L))
  bwDL2 <- prxy %>% getBWremaining()

  testDL1$times["total"]
  testDL2$times["total"]
  
  prxy %>% closeProxy
  
  prxy <- proxy(bmpPort = 9090L, port = 39500L)
  tmpFile <- upload_file(tmp)
  
  # create new HAR for uploads
  prxy %>% createHAR(ref = "httr_upload_1")
  prxy %>% limitBandwidth(downK = 50L)
  testUP1 <- POST("http://httpbin.org/post", httr_proxy(prxy), 
                 body = tmpFile, 
                 config(fresh_connect = 1L))
  # create new page
  prxy %>% newPage(ref = "httr_upnload_2")
  prxy %>% limitBandwidth(downK = 25L)
  
  # empty the DNS cache
  prxy %>% emptyDNS
  testUP2 <- POST("http://httpbin.org/post", httr_proxy(prxy), 
                  body = tmpFile, 
                  config(fresh_connect = 1L))
  
  testUP1$times["total"]
  testUP2$times["total"]
  
  prxy %>% closeProxy

## End(Not run)

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