Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider missing/empty agent to be plaintext #1003

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DavidBuchanan314
Copy link

This PR adds "" (empty string) to the PLAIN_TEXT_AGENTS list.

This means that a client that doesn't set the user-agent header at all (or sets it to an empty string) will be treated as plaintext.

Rationale: A client that doesn't set the UA is likely to be bare-bones, and therefore likely plaintext.

@chubin
Copy link
Owner

chubin commented Jan 16, 2025

@DavidBuchanan314 It will not work like this because of how the agent check is implemented:

html_output = not any(agent in user_agent for agent in PLAIN_TEXT_AGENTS)

It does not check if the string is fully equal to the agent name, but only if the agent name is contained in the user agent header.

Why exactly do you need an empty agent check?

If you absolutely need it, feel free to fix this check:

https://github.com/chubin/wttr.in/blob/master/lib/wttr_srv.py#L166

For example, like this:

agent and not any(agent in user_agent for agent in PLAIN_TEXT_AGENTS)

@chubin chubin self-requested a review January 16, 2025 18:26
Copy link
Owner

@chubin chubin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see above ^^^^^^)

@DavidBuchanan314
Copy link
Author

DavidBuchanan314 commented Jan 16, 2025

any(agent in user_agent for agent in PLAIN_TEXT_AGENTS)

would evaluate to True if user_agent is empty string and PLAIN_TEXT_AGENTS contains empty-string, hence my suggestion.

Your suggestion to edit the expression would work too, though. (I just though it'd be cleaner to have a "data only" change vs a code change but it doesn't really matter either way).

As for why specifically I wanted it, I wrote a code-golfed curl-like program, and thought wttr.in would make a cool demo for it (https://github.com/DavidBuchanan314/kurl) - it does not support setting a UA header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants