Skip to content

Send proper User-Agent string in requests #453

@sirpengi

Description

@sirpengi

Identified as an issue while working on #440 - the Zulip server will automatically mark messages as read for their authors if the client that sent the request is internally identified as a human-powered client (in other words, the message came from an app of some sort rather than a python script).

See sent_by_human in https://github.com/zulip/zulip/blob/main/zerver/models.py#L3238

The name of the client is pulled from the User-Agent header. An initial PR to close #440 was proposed in #450, but that only added a hardcoded User-Agent string as crafting an appropriate one (to match https://github.com/zulip/zulip-mobile/blob/main/src/utils/userAgent.js ) was fraught inside of lib/api/core.dart. Pulling the necessary information out of package_info_plus there broke over a hundred tests as the infrastructure for calculating those values wasn't set up yet.

I think there are a couple options here:

  1. Continue the work of dynamically crafting a User-Agent at send in lib/api/core.dart, figure out the tests.
  2. Craft the User-Agent at a higher level layer, and send that through into the api (such as how we pass zulipFeatureLevel or realmUrl when creating an ApiConnection).

From a cursory look there doesn't appear to be any other use of sent_by_human with other api endpoints, so perhaps this is something that we only need to send when creating a message?

Also see related links:

Additionally, there is a PR in zulip/zulip#28204 that proposes a read_by_sender flag in the API. We could take advantage of this, but will still need a User-Agent for legacy servers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions