Functions for processing the response header of a libcurl request
basicHeaderGatherer.RdThese two functions are used to collect the contents of the header of
an HTTP response via the headerfunction option of a curl handle
and then processing that text into both the name: value pairs
and also the initial line of the response that provides the
status of the request.
basicHeaderGatherer is a simple special case of
basicTextGatherer with the built-in post-processing
step done by parseHTTPHeader.
Usage
basicHeaderGatherer(txt = character(), max = NA)
parseHTTPHeader(lines, multi = TRUE)Arguments
- txt
any initial text that we want included with the header. This is passed to
basicTextGatherer. Generally it should not be specified unless there is a good reason.- max
This is passed directly to
basicTextGatherer- lines
the text as a character vector from the response header that
parseHTTPHeaderwill convert to a status and name-value pairs.- multi
a logical value controlling whether we check for multiple HTTP headers in the lines of text. This is caused by a Continue being concatenated with the actual response. When this is
TRUE, we look for the lines that start an HTTP header, e.g.HTTP 200 ..., and we use the content from the last of these.
Value
The return value is the same as basicTextGatherer,
i.e. a list with
update, value and reset function elements.
The value element will invoke parseHTTPHeader
on the contents read during the processing of the libcurl request
and return that value.
References
Curl homepage https://curl.se/
Examples
tryCatch(withAutoprint({
h = basicHeaderGatherer()
getURI("https://r-project.org",
headerfunction = h$update)
names(h$value())
h$value()
}), GenericCurlError = identity)
#> > h = basicHeaderGatherer()
#> > getURI("https://r-project.org", headerfunction = h$update)
#> [1] "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html><head>\n<title>301 Moved Permanently</title>\n</head><body>\n<h1>Moved Permanently</h1>\n<p>The document has moved <a href=\"https://www.r-project.org/\">here</a>.</p>\n<hr>\n<address>Apache Server at r-project.org Port 443</address>\n</body></html>\n"
#> > names(h$value())
#> [1] "location" "content-length" "content-type" "date"
#> [5] "server" "status" "statusMessage"
#> > h$value()
#> location content-length
#> "https://www.r-project.org/" "338"
#> content-type date
#> "text/html; charset=iso-8859-1" "Thu, 04 Jun 2026 20:37:32 GMT"
#> server status
#> "Apache" "301"
#> statusMessage
#> ""