Skip to content

is_api_request() returns False if content type is not set to "application/json" #20001

@jeremystretch

Description

@jeremystretch

Deployment Type

Self-hosted

NetBox Version

v4.3.5

Python Version

3.10

Steps to Reproduce

  1. Make a REST API GET request without specifying a content type:
curl -v -X GET \
-H "Authorization: Token $TOKEN" \
-H "Accept: application/json; indent=4" \
http://netbox:8000/api/status/
  1. Inspect the response headers.

Expected Behavior

The response should include an API-Version header indicating the NetBox version. This can be verified by re-sending the above request with a Content-Type header:

curl -v -X GET \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
http://netbox:8000/api/status/

Observed Behavior

The API-Version header is missing from the response.

The is_api_request() utility function is intended to return True for any request which qualifies as consuming the REST API. However, this happens only if the request has specified a Content-Type of application/json:

def is_api_request(request):
"""
Return True of the request is being made via the REST API.
"""
api_path = reverse('api-root')
return request.path_info.startswith(api_path) and request.content_type == HTTP_CONTENT_TYPE_JSON

The content type should not be a condition of qualifying as an API request.

Metadata

Metadata

Assignees

Labels

severity: lowDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions