Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#16885 closed defect (bug) (fixed)

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

Reported by: dd32's profile dd32 Owned by: dd32's profile 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 14 years ago.
No notice on missing SP after the three digit HTTP Status-Code
19885.diff (641 bytes) - added by hakre 14 years ago.
default reson phrase is string of status code

Download all attachments as: .zip

Change History (18)

#1 @dd32
14 years ago

  • Description modified (diff)

#2 @dd32
14 years ago

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

#3 @cogmios
14 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 14 years ago by cogmios (previous) (diff)

#4 @hakre
14 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 14 years ago by hakre (previous) (diff)

#5 @hakre
14 years ago

  • Type changed from defect (bug) to enhancement

@hakre
14 years ago

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

#6 @hakre
14 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.

#7 @hakre
14 years ago

  • Keywords has-patch added

@hakre
14 years ago

default reson phrase is string of status code

#8 @cogmios
14 years ago

hakre: are you everywhere? *GRIN*!

#9 @dd32
14 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.

#10 @cogmios
14 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 14 years ago by cogmios (previous) (diff)

#11 @cogmios
14 years ago

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

#12 @dd32
14 years ago

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

#13 follow-up: @azizur
14 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 14 years ago by azizur (previous) (diff)

#14 in reply to: ↑ 13 @hakre
14 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.

#15 @dd32
14 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

#16 @dd32
14 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.