Skip to content

Support for headers per part #567

@alin-a

Description

@alin-a

Hi,

I need to upload files to a server endpoint that requires custom headers on individual multipart parts (e.g. X-checksum for integrity verification on each uploaded file). With curl this is straightforward using the ;headers= suffix on -F:

  curl -X POST "http://localhost:8080/upload" \
    -F 'file=@/path/to/test.md;type=text/plain;headers="X-checksum: some-checksum"'

Unirest's MultipartBody API currently only lets me set Content-Type per part, but there's no way to attach additional headers to a single part.

I can think of two possible solutions:

either: A fluent method on MultipartBody that attaches a header to the most recently added part:

  Unirest.post("http://localhost:8080/upload")
      .field("file", new File("/path/to/test.md"), "text/plain")
      .partHeader("X-checksum", "some-checksum")
      .asString();

or: another overload for .field():

  Headers partHeaders = new Headers();                                                                                                                                                              
  partHeaders.add("X-checksum", "some-checksum");
                                                                                                                                                                                                    
  Unirest.post("http://localhost:8080/upload")                                                                                                                                                    
      .field("file", new File("/path/to/test.md"), "text/plain", partHeaders)
      .asString();    

It does seem, however, that RFC 7578 §4.8 does not allow the setting of custom headers, but would you consider this feature nonetheless? It is supported by other major HTTP clients like curl.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature RequestValid feature request to add to the backlog
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions