WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#16885 closed defect (bug) (fixed)

Warning emited in Header parsing when server does not specify a response "Message"

Reported by: dd32 Owned by: dd32
Milestone: 3.2 Priority: normal
Severity: normal Version: 3.1
Component: HTTP API Keywords: has-patch
Focuses: Cc:

Description (last modified by dd32)

As reported in #16855 by cogmios, the HTTP API class can emit a warning in the case that a server does not specify the response message.

One example of a URL which causes this is: http://wallpapers.protonet.ru/section/foto/O/ which has a response of:

HTTP/1.1 404
Server: nginx/0.6.32

causing:

Undefined offset: 2 in \wp-includes\class-http.php on line <i>442</i>

Code in question: list( , $response['code', $responsemessage?) = explode(' ', $tempheader, 3);]

One potential patch would be:

$p = explode(' ', $tempheader, 3);
array_shift($p);
$response['code'] = array_shift($p);
$response['message'] = array_shift($p);

Attachments (2)

16885.diff (601 bytes) - added by hakre 3 years ago.
No notice on missing SP after the three digit HTTP Status-Code
19885.diff (641 bytes) - added by hakre 3 years ago.
default reson phrase is string of status code

Download all attachments as: .zip

Change History (18)

comment:1 dd323 years ago

  • Description modified (diff)

comment:2 dd323 years ago

  • Owner set to dd32
  • Status changed from new to accepted

comment:3 cogmios3 years ago

the patch as proposed does not solve the issue since then you would get;

"Notice: Undefined offset: 1 i" etc... instead

ALSO: The code i put in the other ticket with first checking the count is not the complete answer since that also give the notice on "1"

Last edited 3 years ago by cogmios (previous) (diff)

comment:4 hakre3 years ago

As that is a HTTP/1.1 response, the server is violating the HTTP specification.

The Reason-Phrase of the Status-Line in HTTP Resonse Messages is not optional. However our HTTP client is not required to examine or display the Reason-Phrase so I think it's okay to deal with a missing SP and phrase.

I think it's worth to report that problem with the NGINX project.

See 6.1 Status-Line (http 1.1, for http 1.0)

Last edited 3 years ago by hakre (previous) (diff)

comment:5 hakre3 years ago

  • Type changed from defect (bug) to enhancement

hakre3 years ago

No notice on missing SP after the three digit HTTP Status-Code

comment:6 hakre3 years ago

Default Response Phrase is Empty. The RFC offers some default Phrases, but IMHO that would be a bit much to provide for a buggy HTTP server resonse.

comment:7 hakre3 years ago

  • Keywords has-patch added

hakre3 years ago

default reson phrase is string of status code

comment:8 cogmios3 years ago

hakre: are you everywhere? *GRIN*!

comment:9 dd323 years ago

the patch as proposed does not solve the issue since then you would get;

"Notice: Undefined offset: 1 i" etc... instead

How did you get that? array_shift() will return null on an empty array/non-array.

comment:10 cogmios3 years ago

"Notice: Undefined offset: 1 in C:\xampp\htdocs\wp2\wp-includes\class-http.php on line 457"....
I assumed it was the changed code..... but was this line after it..... :

list($key, $value) = explode(':', $tempheader, 2);

because i dropped the continue, sry

if ( false === strpos($tempheader, ':') ) {
$p = explode(' ', $tempheader, 3);
array_shift($p);
$response['code'] = array_shift($p);
$response['message'] = array_shift($p);
continue;
}
Last edited 3 years ago by cogmios (previous) (diff)

comment:11 cogmios3 years ago

@hakre i think you are right, more threads on nginx missing phrases on google.

comment:12 dd323 years ago

  • Component changed from Warnings/Notices to HTTP
  • Type changed from enhancement to defect (bug)

comment:13 follow-up: azizur3 years ago

  • Cc azizur added

Not sure if this related and if it could be address at the time.

When the fetching a url for rss which is unreachable you also get:

Warning: Invalid argument supplied for foreach() in {path-to}/wp-includes/class-http.php on line 362

RSS Error: A feed could not be found at http://my-disfunctional-url.org/news/feed/

This is not helpful to average users/subscribers when they see this once they are re-directed to dashboard after login.

Want to re-produce it?
Go to Dashboard and change the "WordPress Blog" or "Dashboard Primary" widget url to something that does not work.

Last edited 3 years ago by azizur (previous) (diff)

comment:14 in reply to: ↑ 13 hakre3 years ago

Replying to azizur:
Which transport is that? I get RSS Error: WP HTTP Error: Could not open handle for fopen() to http://my-disfunctional-url.org/news/feed/ on current trunk. Probably because of the transport or the recent changes.

comment:15 dd323 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [17599]) Fix warning in HTTP Header parsing where response message is not specified. Props hakre. Fixes #16885

comment:16 dd323 years ago

  • Milestone changed from Awaiting Review to 3.2

went with the empty message field since that's what the server is returning.

The message can be absolutely anything "HTTP/1.1 200 Woot!" is a completely valid response, although discouraged. Any code should be validating based on the response code, so an empty message is not the end of the world.

Note: See TracTickets for help on using tickets.