Opened 4 years ago

Closed 3 years ago

#32397 closed Cleanup/optimization (fixed)

django-admin start[project|app] doesn't send proper user agent header when HTTP(S) url is sent.

Reported by: rsp2k Owned by: Ad Timmering
Component: Core (Management commands) Version: 3.1
Severity: Normal Keywords:
Cc: Ad Timmering Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by rsp2k)

By default, when fetching a remote template, django-admin start[app|project] uses the default urllib User Agent which causes some sites to block requests (namely gitlab, since they use cloudflare See https://gitlab.com/gitlab-org/gitlab/-/issues/219669).

This patch sets the 'User Agent' header to Django/DJANGO_VERSION.

Attachments (1)

add-user-agent-to-django-admin-templates.diff (1.8 KB ) - added by rsp2k 4 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 by rsp2k, 4 years ago

Description: modified (diff)

comment:2 by rsp2k, 4 years ago

Owner: rsp2k removed
Status: assignednew

comment:3 by Carlton Gibson, 4 years ago

Needs tests: set
Resolution: needsinfo
Status: newclosed
Type: New featureCleanup/optimization

Hi rsp2k.

I'm inclined to accept this — no problem setting the User-Agent.

Initially though I'm going to close as needsinfo — that info being, are you up for finishing this?

I see you removed your assignment, but the patch needs tests. Specifically they could go in django/tests/admin_scripts/tests.py in the StartProject and StartApp classes.

If so can you add the tests, open a PR on GitHub, re-open the ticket, and assign yourself again?
Thanks.

comment:4 by rsp2k, 4 years ago

Resolution: needsinfo
Status: closednew

Thank you for your reply. I am working on the tests now and will follow the steps you outlined.

I took myself off the ticket because I thought it might not get routed properly, my mistake. I'm reassigning it now.

comment:5 by rsp2k, 4 years ago

Owner: set to rsp2k
Status: newassigned

comment:6 by Carlton Gibson, 4 years ago

Triage Stage: UnreviewedAccepted

Super, thanks for the follow-up! Let's accept for review. Welcome aboard!

comment:7 by Ad Timmering, 3 years ago

Cc: Ad Timmering added
Needs tests: unset

Have taken the liberty of adding tests to rsp2k's patch in this PR.

Feels like there should be a cleaner way to get the UA from the request; ideas very welcome.

comment:8 by Mariusz Felisiak, 3 years ago

Patch needs improvement: set

comment:9 by Ad Timmering, 3 years ago

Owner: changed from rsp2k to Ad Timmering
Patch needs improvement: unset

PR updated reflecting feedback, and rebased to main.

comment:10 by Mariusz Felisiak, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In 9a6e2df3:

Fixed #32397 -- Made startapp/startproject management commands set User-Agent.

This sets User-Agent to 'Django/<version>'.

Note: See TracTickets for help on using tickets.
Back to Top