php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77442 cURL ignores last header in CURLOPT_HTTPHEADER
Submitted: 2019-01-11 06:26 UTC Modified: 2019-04-07 04:22 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: stian at octetnest dot no Assigned:
Status: No Feedback Package: cURL related
PHP Version: 7.1.26 OS: Ubuntu 16.04
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-01-11 06:26 UTC] stian at octetnest dot no
Description:
------------
cURL seems to always ignore the last header set through CURLOPT_HTTPHEADER. When I inspect outgoing requests with Wireshark, it consistently shows that the last header in an headers array provided to cURL gets ignored. For the headers provided in the 'Test Script' field, this is what Wireshark reports (The 'X-Remove' header is gone) :

POST [REMOVED] HTTP/1.1
Host: [REMOVED]
Accept: */*
Accept-Encoding: application/xml
X-External-User-ID: 1
X-Territory-ID: 9b0a8426-1493-4997-aab0-2d0de736225a
X-Company-Name: Company Name
X-File-Quality: 1
X-File-Type: JPG
X-Filename-Prefix: prefix
X-Title: Title
Authorization: Basic dGVzdDp0ZXN0
X-Trace: 2B2B1AB863BA48CFF980DCE0B5CD3C3FE7DD4E68390B4A407CEEBFEBC601

If I take out the 'X-Remove' header, then cURL will ignore the 'Authorization' header. 

Test script:
---------------
$headers = array(
  'X-External-User-ID: 1',
  'X-Territory-ID: 9b0a8426-1493-4997-aab0-2d0de736225a',
  'X-Company-Name: Company Name',
  'X-File-Quality: 1',
  'X-File-Type: JPG',
  'X-Filename-Prefix: prefix',
  'X-Title: Title',
  'Authorization: Basic dGVzdDp0ZXN0',
  'X-Remove: This header will be removed by curl',
);

$curl = curl_init();
  curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "application/xml",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 3,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => $method,
    CURLOPT_HEADER => 1,
    CURLOPT_HTTPHEADER => array_values($headers)
  ));


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-28 18:46 UTC] kontakt at beberlei dot de
I cannot reproduce this on 7.1 and ubuntu 18.04.

Could you say which vrsion of curl are you using from phpinfo? I have cURL Information => 7.58.0

One thing that I think is the cause is the "X-Trace" header. Is there an extension injecting this header? It isn't in your list of curl_setopt_array
 [2019-03-26 12:11 UTC] mike@php.net
-Status: Open +Status: Feedback
 [2019-04-07 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 14:01:29 2024 UTC