HTTP Request, Response and URL Parser
https://cinc.rud.is/web/packages/construe/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
boB Rudis
5622e1e712
|
4 years ago | |
---|---|---|
R | 4 years ago | |
inst/tinytest | 4 years ago | |
man | 4 years ago | |
src | 4 years ago | |
tests | 4 years ago | |
.Rbuildignore | 4 years ago | |
.codecov.yml | 4 years ago | |
.gitignore | 4 years ago | |
.travis.yml | 4 years ago | |
CONDUCT.md | 4 years ago | |
DESCRIPTION | 4 years ago | |
LICENSE | 4 years ago | |
LICENSE.md | 4 years ago | |
NAMESPACE | 4 years ago | |
NEWS.md | 4 years ago | |
README.Rmd | 4 years ago | |
README.md | 4 years ago | |
appveyor.yml | 4 years ago | |
construe.Rproj | 4 years ago |
README.md
construe
HTTP Request, Response and URL Parser
Description
A simple and fast HTTP request, response and URL parser based on the C++ ‘httpparser’ library by Alex Nekipelov (https://github.com/nekipelov/httpparser).
What’s Inside The Tin
The following functions are implemented:
parse_request
: Parse an HTTP requestparse_response
: Parse an HTTP responseparse_url
: Parse URLs
Installation
install.packages("construe", repos = c("https://cinc.rud.is", "https://cloud.r-project.org/"))
# or
remotes::install_git("https://git.rud.is/hrbrmstr/construe.git")
# or
remotes::install_git("https://git.sr.ht/~hrbrmstr/construe")
# or
remotes::install_gitlab("hrbrmstr/construe")
# or
remotes::install_bitbucket("hrbrmstr/construe")
# or
remotes::install_github("hrbrmstr/construe")
NOTE: To use the ‘remotes’ install options you will need to have the {remotes} package installed.
Usage
library(construe)
# current version
packageVersion("construe")
## [1] '0.1.0'
Requests
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
parse_request(req)
## $method
## [1] "GET"
##
## $uri
## [1] "/uri.cgi"
##
## $vers_maj
## [1] 1
##
## $vers_min
## [1] 1
##
## $keepalive
## [1] TRUE
##
## $headers
## name value
## 1 User-Agent Mozilla/5.0
## 2 Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
## 3 Host 127.0.0.1
##
## $content
## character(0)
##
## attr(,"class")
## [1] "http_request" "list"
microbenchmark::microbenchmark(
parse_request = parse_request(req)
)
## Unit: microseconds
## expr min lq mean median uq max neval
## parse_request 278.215 301.504 325.0598 311.175 323.4045 615.78 100
Responses
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
parse_response(resp)
## $status_msg
## [1] "OK"
##
## $status_code
## [1] 200
##
## $vers_maj
## [1] 1
##
## $vers_min
## [1] 1
##
## $keepalive
## [1] TRUE
##
## $headers
## name value
## 1 Server nginx/1.2.1
## 2 Content-Type text/html
## 3 Content-Length 8
## 4 Connection keep-alive
##
## $content
## [1] "<" "h" "t" "m" "l" " " "/" ">"
##
## attr(,"class")
## [1] "http_response" "list"
microbenchmark::microbenchmark(
parse_response = parse_response(resp)
)
## Unit: microseconds
## expr min lq mean median uq max neval
## parse_response 276.707 295.5835 318.2582 303.949 318.0525 533.422 100
URLs
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://username@www.example.com/dir/subdir?param=1¶m=2;param%20=%20#fragment",
"http://username:passwd@www.example.com/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:passwd@www.example.com:8080/dir/subdir?param=1¶m=2;param%20=%20#fragment",
"ftp://username:passwd@ftp.example.com/dir/filename.ext",
"mailto:username@example.com",
"svn+ssh://hostname-01.org/path/to/file",
"xddp::://///blah.wat/?"
) -> turls
parse_url(turls)
## scheme username password hostname port path query fragment
## 1 git+ssh example.com /path/file
## 2 https example.com /path/file
## 3 http www.example.com /dir/subdir param=1¶m=2;param%20=%20 fragment
## 4 http www.example.com /
## 5 http username www.example.com /dir/subdir param=1¶m=2;param%20=%20 fragment
## 6 http username passwd www.example.com /dir/subdir param=1¶m=2;param%20=%20 fragment
## 7 http www.example.com 8080 /dir/subdir param=1¶m=2;param%20=%20 fragment
## 8 http username passwd www.example.com 8080 /dir/subdir param=1¶m=2;param%20=%20 fragment
## 9 ftp username passwd ftp.example.com /dir/filename.ext
## 10 mailto username example.com /
## 11 svn+ssh hostname-01.org /path/to/file
## 12 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
microbenchmark::microbenchmark(
parse_url = parse_url(turls[1])
)
## Unit: microseconds
## expr min lq mean median uq max neval
## parse_url 697.76 755.4585 832.5939 777.1725 871.3295 1311.091 100
construe Metrics
Lang | # Files | (%) | LoC | (%) | Blank lines | (%) | # Lines | (%) |
---|---|---|---|---|---|---|---|---|
C/C++ Header | 5 | 0.23 | 1561 | 0.44 | 120 | 0.29 | 54 | 0.20 |
C++ | 2 | 0.09 | 162 | 0.05 | 55 | 0.13 | 20 | 0.07 |
Rmd | 1 | 0.05 | 49 | 0.01 | 28 | 0.07 | 37 | 0.14 |
R | 3 | 0.14 | 13 | 0.00 | 6 | 0.01 | 25 | 0.09 |
SUM | 11 | 0.50 | 1785 | 0.50 | 209 | 0.50 | 136 | 0.50 |
clock Package Metrics for construe
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.