-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
185 lines (136 loc) · 3.74 KB
/
README.Rmd
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
---
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
---
```{r pkg-knitr-opts, include=FALSE}
hrbrpkghelpr::global_opts()
```
```{r badges, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::stinking_badges(branch = "batman")
```
```{r description, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::yank_title_and_description()
```
## What's Inside The Tin
The following functions are implemented:
```{r ingredients, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::describe_ingredients()
```
## Installation
```{r install-ex, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::install_block()
```
## Usage
```{r lib-ex}
library(construe)
# current version
packageVersion("construe")
```
### Requests
```{r ex01}
paste0(c(
"GET /uri.cgi HTTP/1.1\r\n",
"User-Agent: Mozilla/5.0\r\n",
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n",
"Host: 127.0.0.1\r\n", "\r\n"
), collapse = "") -> req
req_raw <- charToRaw(req)
parse_request(req)
parse_request_raw(req_raw)
microbenchmark::microbenchmark(
parse_request = parse_request(req),
parse_request_raw = parse_request_raw(req_raw)
)
```
### Responses
```{r ex02}
paste0(c(
"HTTP/1.1 200 OK\r\n",
"Server: nginx/1.2.1\r\n",
"Content-Type: text/html\r\n",
"Content-Length: 8\r\n",
"Connection: keep-alive\r\n",
"\r\n",
"<html />"
), collapse = "") -> resp
resp_raw <- charToRaw(resp)
parse_response(resp)
parse_response_raw(resp_raw)
microbenchmark::microbenchmark(
parse_response = parse_response(resp),
parse_response_raw = parse_response_raw(resp_raw)
)
```
### curl output example
`HEAD` request:
```{r curl-01}
sys::exec_internal(
cmd = "curl",
args = c("--include", "--head", "--silent", "https://httpbin.org/")
) -> res
str(parse_response(rawToChar(res$stdout)), 2)
curl::curl_fetch_memory(
"https://httpbin.org/",
handle = curl::new_handle(
nobody = TRUE
)
) -> res
str(construe::parse_response_raw(res$headers), 2)
curl::curl_fetch_memory(
"http://rud.is/b",
handle = curl::new_handle(
nobody = TRUE,
followlocation = TRUE
)
) -> res
rawToChar(res$headers) %>%
strsplit("(?m)\r\n\r\n", perl = TRUE) %>%
unlist() %>%
lapply(construe::parse_response) %>%
str(2)
```
`GET` request:
```{r curl-02}
sys::exec_internal(
cmd = "curl",
args = c("--include", "--silent", "https://httpbin.org/")
) -> res
str(parse_response_raw(res$stdout), 2)
res <- curl::curl_fetch_memory("https://httpbin.org/")
str(construe::parse_response_raw(res$headers), 2)
```
### URLs
```{r ex03}
c(
"git+ssh://example.com/path/file",
"https://example.com/path/file",
"http://www.example.com/dir/subdir?param=1¶m=2;param%20=%20#fragment",
"http://www.example.com",
"http://[email protected]/dir/subdir?param=1¶m=2;param%20=%20#fragment",
"http://username:[email protected]/dir/subdir?param=1¶m=2;param%20=%20#fragment",
"http://www.example.com:8080/dir/subdir?param=1¶m=2;param%20=%20#fragment",
"http://username:[email protected]:8080/dir/subdir?param=1¶m=2;param%20=%20#fragment",
"ftp://username:[email protected]/dir/filename.ext",
"mailto:[email protected]",
"svn+ssh://hostname-01.org/path/to/file",
"xddp::://///blah.wat/?"
) -> turls
parse_url(turls)
microbenchmark::microbenchmark(
parse_url = parse_url(turls[1])
)
```
### Parse headers from Palo Alto `HEAD` requests
```{r why}
hdr <- read_file_raw(system.file("extdat", "example.hdr", package = "construe"))
cat(rawToChar(hdr))
parse_response_raw(hdr)
```
## construe Metrics
```{r cloc, echo=FALSE}
cloc::cloc_pkg_md()
```
## Code of Conduct
Please note that this project is released with a Contributor Code of Conduct.
By participating in this project you agree to abide by its terms.