metafacture / metafacture-core

Core package of the Metafacture tool suite for metadata processing.
https://metafacture.org
Apache License 2.0
69 stars 34 forks source link

Generic header support in HttpOpener #456

Closed fsteeg closed 1 year ago

fsteeg commented 2 years ago

Requirement from OERSI: provide a way to set custom headers on the HTTP connection, e.g. x-api-key: 123456780.

We could add a generic setHeader option to HttpOpener, used in flux like open-http(header="x-api-key: 123456780").

blackwinter commented 2 years ago

What about multiple headers? Can Flux accept multiple parameters of the same name? Or would we have to find a different mechanism?

blackwinter commented 2 years ago

I have an implementation ready for the simple case (single header). Once we decide how to deal with multiple headers, I can open a pull request.

fsteeg commented 2 years ago

We could use an & like for query parameters, e.g.:

open-http(header="x-header-1:abc&x-header-2:123")

This is also used for the attributeValuesAsSubfields option in HtmlDecoder.

blackwinter commented 2 years ago

But then you can't set a header with & in its value. Is this a sufficiently uncommon character to be suitable as separator?

blackwinter commented 2 years ago

Can Flux accept multiple parameters of the same name?

No, it can't (uses a Map to collect the named arguments).

fsteeg commented 2 years ago

But then you can't set a header with & in its value.

We could expect the individual headers header values to be URI-encoded (e.g. %26 for &).

blackwinter commented 2 years ago

Hm, we could, but I'm not really sure that's a reasonable assumption. After all, what do header values have to do with URIs?

It would be possible to enable duplicate named arguments in Flux (with Map<String, List<String>>), but that would be an incompatible change (and has somewhat of a ripple effect).

Maybe we should wait for others to weigh in before we decide?

blackwinter commented 2 years ago

We could use \n which is an invalid character (see 80235d6 for a possible implementation).