Skip to content

Course assets should be served by a view rather than a middleware #34702

Description

@timmc-edx

Acceptance criteria:

  • StaticContentServer is converted from a middleware to a view
  • The cutover is managed with a Waffle flag or similar to allow careful rollout
  • Documentation added to next Open edX named-release notes
  • Optional: Additional cleanup
    • Remove temporary IMPL variable and StaticContentServer class by lifting methods to module scope
    • Separate views for different URL patterns

Course asset URLs like /asset-v1:... are served from a middleware at openedx.core.djangoapps.contentserver.middleware.StaticContentServer rather than from a view. This means that Django starts handling the request as a Not Found (because there is no matching urlpattern), but then the middleware intercepts the request and returns a response of its own. There wasn't any good reason for doing this instead of using a view, as far as I can tell. It causes some problems for telemetry: When the code-owner middleware asks Django what view handled the request, it does so by looking at the result of the resolve utility, but these URLs get a Resolver404 (because there's no registered urlpattern).

Implementation suggestion:

  1. Register equivalent urlpatterns and a view that calls into the same code the middleware currently contains.
  2. Add a Waffle flag that causes the middleware to fall through to the view.
  3. Try turning the flag on.
  4. Remove the middleware so that the view is always used.
  5. [Beyond this ticket:] Bring the new view's code up to standards (better use of urlpatterns, etc.)

PRs:

Metadata

Metadata

Assignees

Labels

code healthProactive technical investment via refactorings, removals, etc.maintenanceRoutine upkeep necessary for the health of the platform

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions