Skip to content

Header Content is split on Comma #187

@DavZim

Description

@DavZim

All header values are split on comma.
This breaks for example the If-Modified-Since functionality of ETags as it uses the (ugly but sadly standard) "Tue, 15 Mar 2022 10:27:07 GMT" format.

According to this not all headers should be split on comma.

This is not present when RestRserve::Request and app$process_request(req) is used for some reasons.

Is this intended or a bug/not-yet-implemented-feature?

If confirmed, I am happy to help.

Replication

Replicate the issue with the following:

library(RestRserve)

print_headers = Middleware$new( 
  process_request = function(.req, .res) print(.req$headers),
  process_response = function(.req, .res) {},
  id = "print_headers"
)
app = Application$new()
app$append_middleware(print_headers)
app$add_get("/foo", FUN = function(.req, .res) .res$body = 42)

# Test using RestRserve::Request works
req = Request$new(
  path = "/static/example-text-file",
  method = "GET",
  headers = list("If-Modified-Since" = "Tue, 15 Mar 2022 10:27:07 GMT")
)

# the header is not split on the comma! We get one date - CORRECT!
rs = app$process_request(req)
#> $`if-modified-since`
#> [1] "Tue, 15 Mar 2022 10:27:07 GMT"

# start the server
backend = BackendRserve$new()
backend$start(app, http_port = 8080)

Now we can see the issue either by using curl:

curl http://localhost:8080/foo -H "If-Modified-Since: Tue, 15 Mar 2022 10:27:07 GMT"

which results in

#> $`if-modified-since`
#> [1] "Tue"                      "15 Mar 2022 10:27:07 GMT"

Note that providing the header as "If-Modified-Since: \"Tue, 15 ...\"" does not change the outcome.

or by using httr:

httr::GET("http://localhost:8080/foo",
          httr::add_headers("If-Modified-Since" = "Tue, 15 Mar 2022 10:27:07 GMT"))

which also results in

#> $`if-modified-since`
#> [1] "Tue"                      "15 Mar 2022 10:27:07 GMT"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions