Tyk Python middleware capability to set response

Is there any way to set the response using Python middleware and prevent request to be proxied to origin?
Let’s say I have service that should return JSON based on request content if header is set or call the actual origin service if there’s no header.