Okay, now it kind of works (thanks José and Kilian). I can see in the debugger that it assigns the value from the header to the custom response but then afterwards it doesn't return to its normal flow. It seems that it triggers an exception after the "OnAfterResponse" callback but the exception is completely empty (no message, no code or whatever).
Any clue why this is happening?