Skip to content

Bug: Multiple Expires and Cache-Control Headers in File Download Response #9234

@ToastStudios

Description

@ToastStudios

PHP Version

8.1

CodeIgniter4 Version

4.5.5

CodeIgniter4 Installation Method

Manual (zip or tar.gz)

Which operating systems have you tested for this bug?

macOS, Linux

Which server did you use?

apache

Database

mysql Ver 8.3.0 for macos14.2 on arm64 (Homebrew)

What happened?

While implementing a file download feature in a CodeIgniter 4 application, I encountered an issue where multiple Expires and Cache-Control headers were being sent in the HTTP response. This problem occurred despite attempts to explicitly set these headers using the framework's response methods.

Steps to Reproduce

  1. Create a controller method to serve a file download (e.g., CRL file).
  2. Use the response object to set custom headers, such as Content-Type, Last-Modified, and Expires.
  3. Attempt to remove existing headers using $response->removeHeader().
  4. Observe that multiple Expires and Cache-Control headers are still present in the HTTP response.

Expected Output

Only one instance of each header should be sent in the response, specifically the ones set in the controller method.

Anything else?

As a workaround, the issue was resolved by using native PHP functions (header() and readfile()) to manage headers directly, bypassing CodeIgniter’s response handling. This provided complete control over the headers sent, eliminating the duplication issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions