connexion icon indicating copy to clipboard operation
connexion copied to clipboard

Warning is logged for endpoints returning no content

Open alfechner opened this issue 1 year ago • 0 comments

My service has an endpoint to check weather it's healthy or not.

Spec:

/health:
  get:
    operationId: my_service.controllers.monitoring_controller.get_health
    security: []
    description: Checks the health status of the service. Does not include connected services.
    tags:
      - "Monitoring"
    responses:
      204:
        description: "Healthy"

Controller:

def get_health():
    return None, 204

On request the server logs a warning: Skipping validation. No validator registered for content type: application/octet-stream. Those logs flood our monitoring because the health endpoint is called pretty often.

I worked around this issue with the following change:

from starlette.responses import Response

def get_health():
    return Response(content=None, status_code=204, media_type="application/json")

It looks like the absence of a content type in case of an empty response causes the server to fall back to media type application/octet-stream.

I'd expect no response validation and therefore not log entry if there is no response content.

alfechner avatar Jan 05 '24 11:01 alfechner