Closed ub1k24 closed 4 years ago
In scope:
"<knotx:(?<type>\\w+)(?<attributes>.*?[^>])>(?<body>.*?)</knotx:\\1>"
with tree predefined groups: type
, attributes
and body
I reviewed the logic from the HtmlFragmentsSupplier
one more time. And I must admit I find it quite bad decision to throw an exception when supplier is not able to produce any fragments.
I guess that's too much responsibility, which should be handled somewhere else (e.g. at the Repository Connector level).
I'd suggest to remove the check for empty body
and just produce an empty list of fragments, when the supplier is not able to provide anything meaningful from the request context (client response).
@tomaszmichalak , @ub1k24 WDYT?
From my perspective it's perfectly fine to do as you say. This was my initial thought that HtmlFragmentsSupplier
should not fail on empty body
.
There is one more logic to consider.
Currently FragmentsAssemblerHandler
sets status code 200
when merging fragments.
It wasn't a problem previously, when there was no body and exception was thrown in the HtmlFragmentsSupplier
. Currently, when empty fragments list is processed by FragmentsAssemblerHandler
it still overrides the status code (SC) to 200
.
I can think of following scenarios to update that logic, so that 302
is returned in the server response:
Update FragmentsAssemblerHandler
SC logic
200
only when body is not empty (case for API Gateway & Web API)Set 200
in client response at the beginning of processing and remove logic for SC from assembler
Update ResponseWriterHandler
(exactly ServerResponse
) logic to set SC according to:
200
500
What is worth remembering, any Handler can modify the clientResponse SC (currently there are 3 such handlers: both repo connector, and assembler). I hesitate between options (1) (change scope limited to fragments repository) and (3) (looks like a proper place to have SC logic in one place).
It looks that (2) is already happening: https://github.com/Knotx/knotx-server-http/blob/2.2.0/api/src/main/java/io/knotx/server/api/context/RequestContext.java#L42
Is your feature request related to a problem? Please describe.
HtmlFragmentsSupplier
processes 302 same as 200 responses which makes it fail on the lack of html body in the responseDescribe the solution you'd like
HtmlFragmentsSupplier
should have an ability to pass with no error 302 responses directly through to further handlersDescribe alternatives you've considered
HtmlFragmentsSupplier
could be configurable toallowEmpty
html body - with a config flagAdditional context This causes AEM integration fail on authoring, whenever user accesses a page through knotx when not logged in