FWIW, the spec clarified the behavior in JAX-RS 3.1[1].  Prior to that, it
was unclear whether the getRequestHeader() method should return a list vs
returning null.  The 3.1 behavior states that it should return null if the
header is not present, but afaik CXF does not yet implement the 3.1 spec.

Notice from the footnote that different JAX-RS implementations (like
RESTEasy) have different behaviors for this method.  So to be on the safe
side, I would suggest coding your app to expect either null or an empty
list - in your case (a list with a single null entry), it sounds more like
a bug to me.

Hope this helps,

Andy

[1] https://github.com/jakartaee/rest/issues/944

On Wed, Jan 11, 2023 at 8:36 AM Erich Mauerböck <e...@kabsi.at> wrote:

> Hi,
>
> no, I didn't. I was referring to the request only. Forget about the
> response by now. By setting the content-type header in a request, the
> client tells the server what type of data it wants to send in the body.
> As I am using a GET request, no such header needs to be present, so I
> omit it. However my mentioned server side code actually gives me such a
> header via injected HttpHeaders object, but it has a null value.
>
> Cheers,
> Erich.
>
> Am 2023-01-11 15:17, schrieb tomee-u...@web.de:
> > Hi Erich,
> >
> > I assume you mixed client/server behaviour.
> >
> > The client fetchtes the data from server. Normally it uses the Accept
> > Header to tell the client which data format will be accepted.
> > The server sends the data with the content-type header.
> >
> > For example: When the client ask for data with:
> > Accept: application/json application/text
> >
> > The server answers with
> > Content-Type: application/json
> >
> > In this case the client knows that the data are json encoded and not
> > xml.
> >
> > When you using a POST request the client sends data. In this case the
> > content-tpye header must be set otherwise the server does not know
> > about the data format and need a method which handles the request.
> >
> > Cheers,
> > Markus
> >
> >> Gesendet: Dienstag, 10. Januar 2023 um 19:36 Uhr
> >> Von: "Erich Mauerböck" <e...@kabsi.at>
> >> An: users@cxf.apache.org
> >> Betreff: Injected null Content-Type header?
> >>
> >> Hi,
> >>
> >> I am using CXF 3.5.5 as JAXRS implementation. Today I got a null
> >> Content-Type header injected via the following code:
> >>
> >> @GET
> >> public void someMethod(@Context HttpHeaders headers) {
> >>    ...
> >> }
> >>
> >> Calling this method without a Content-Type header (which makes no
> >> sense
> >> with a GET request) did the following:
> >> While headers.getMediaType() returned null as expected, I was also
> >> expecting headers.getRequestHeaders().get("Content-Type") to return
> >> null, but actually I got a List with one String element being null.
> >> May
> >> this be a bug?
> >>
> >> BR
> >> Erich.
> >>
>

Reply via email to