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: -
From: stian at octetnest dot no Assigned:
Status: Open 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

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Jan 16 12:01:25 2019 UTC