Skip to content

Unable to handle req_stream errors due to stream open throwing an error #137

@DMerch

Description

@DMerch

I'm writing an API wrapper that POSTs a command to the server via req_stream to select which data to return. If the posted body is malformed, the server responds with error code 400 causing the open command within req_stream to throw an error. The error prevents the subsequent reading of the error contents by the callback and prevents the subsequent creation of a new_response return value containing the status code.

The R curl_fetch_stream function does not suffer this same limitation because it opens the stream using "rbf" mode instead of "rb" mode. According to the curl's internal code comment, "# 'f' means: do not error for status code".

I request that req_stream be modified such that

stream <- curl::curl(req$url, handle = handle)
open(stream, "rb")

becomes

stream <- curl::curl(req$url, handle = handle)
open(stream, "rbf")

My local testing shows that this change prevents R from throwing an error, allows subsequent parsing of the stream contents, and correctly creates the new_response code with the observed status code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions