Skip to content

API improperly sends cache headers #8979

Open
@tsummerer

Description

@tsummerer

Issue

Due to some changes in the .htaccess file (see #7909), since 7.11.9, API requests are sending a cache header for 1 month.

This causes some API libraries (such as ionic's http) to not make additional http requests and can cause client applications to show incorrect data.

The root problem is that the API always returns a Content Type of application/vnd.api+json while the .htaccess file targets types of application/json

Expected Behavior

All API requests should have an Expiration of 0 seconds in the future. They should have headers which would prevent caching

Actual Behavior

API requests return the following headers:

Cache-Control : max-age=2592000
Expires : [Now + 30 days]

Possible Fix

Update the .htaccess file to target application/vnd.api+json together with application/json

Alternatively, set headers explicitly in Api/V8/Controller/BaseController.php (or perhaps have the container return a Response that has been preconfigured with appropriate headers)

Steps to Reproduce

  1. Authenticate with the API : {{INSTANCEURL}}/Api/access_token
  2. Perform a GET request : {{INSTANCEURL}}/Api/V8/module/Accounts
  3. View the response headers

Context

We have a mobile app that is built on the widely used Ionic Framework. When our app would query the CRM API it would get a response (say, a list of Tasks). We might add a Task and then query the list again. Because CRM instructed the client to cache the data for 30 days, the client did not actually perform the second query - but simply returned from cache - so we never saw the new Task.

Your Environment

  • SuiteCRM Version used: 7.11.18
  • Browser name and version (e.g. Chrome Version 51.0.2704.63 (64-bit)): Chrome
  • Environment name and version (e.g. MySQL, PHP 7): LAMP - PHP 7.1, MySQL 5.8
  • Operating System and version (e.g Ubuntu 16.04):Ubuntu 16.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: APIIssues & PRs related to all things regarding the APIPriority:ImportantIssues & PRs that are important; broken functions, errors - there are workaroundsType: BugBugs within the core SuiteCRM codebase

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions