Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

application/openmetrics-text encoding cannot be selected in asgi app using the Accept header  #861

Copy link
Copy link
Closed
@jezekra1

Description

@jezekra1
Issue body actions

The openmetrics format cannot be selected using the Accept: application/openmetrics-text header, because there is the extra header key in the beginning in asgi.py:make_asgi_app which I believe is incorrect. Compare with the accept_encoding_header just below.
https://github.com/prometheus/client_python/blob/master/prometheus_client/asgi.py#L15:

         # Accept header key here:
        accept_header = "Accept: " + ",".join([
            value.decode("utf8") for (name, value) in scope.get('headers')
            if name.decode("utf8").lower() == 'accept'
        ])
        # No header key here:
        accept_encoding_header = ",".join([
            value.decode("utf8") for (name, value) in scope.get('headers')
            if name.decode("utf8").lower() == 'accept-encoding'
        ])

The condition in exposition.py is thus comparing the full header:

accepted.split(';')[0].strip() results to Accept: application/openmetrics-text.

def choose_encoder(accept_header: str) -> Tuple[Callable[[CollectorRegistry], bytes], str]:
    accept_header = accept_header or ''
    for accepted in accept_header.split(','):
        if accepted.split(';')[0].strip() == 'application/openmetrics-text':
            return (openmetrics.generate_latest,
                    openmetrics.CONTENT_TYPE_LATEST)
    return generate_latest, CONTENT_TYPE_LATEST

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.