R/get_boundary.R

Defines functions get_boundary

get_boundary <- function(content_type){
  # Check for multipart header
  if(!grepl("multipart/form-data;", content_type, fixed = TRUE))
    stop("Content type is not multipart/form-data: ", content_type)
  if(!grepl("boundary=", content_type, fixed = TRUE))
    stop("Multipart content-type header without boundary: ", content_type)

  # Extract bounary
  m <- regexpr('boundary=[^; ]{2,}', content_type, ignore.case = TRUE)
  boundary <- sub('boundary=','',regmatches(content_type, m)[[1]])
  sub('^"(.*)"$', "\\1", boundary)
}

Try the webutils package in your browser

Any scripts or data that you put into this service are public.

webutils documentation built on Nov. 24, 2023, 5:11 p.m.