WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#42240 closed defect (bug) (fixed)

Improve returned status codes for admin-ajax.php

Reported by: Clorith Owned by: SergeyBiryukov
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.9
Component: Administration Keywords: has-patch
Focuses: Cc:

Description

in r41120 a status code of 400, Bad Request, was introduced if no request data was provided, but it also makes 400 the default code if the file is left to run till the end.

Anything using admin-ajax.php would normally end execution once it's done, for better performance, but in some cases it may be desirable to execute multiple actions based on an ajax call.

@westonruter mentioned we could do an has_action() check and still send a 400 code if there's no registered action for the request, and use 200 as the status if an action exists but it just didn't end execution.

Attachments (1)

42240.patch (1.0 KB) - added by Clorith 3 years ago.

Download all attachments as: .zip

Change History (4)

@Clorith
3 years ago

#1 @Clorith
3 years ago

  • Keywords has-patch added

42240.patch reverts the default response to not declare a specific response code (as it was previously), but also introduces checks for has_action() and returns a bad request if no action has been registered.

#2 @SergeyBiryukov
3 years ago

  • Component changed from General to Administration

#3 @SergeyBiryukov
3 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 41926:

Administration: After [41120], check for a registered action before sending a Bad Request HTTP response status code.

Props Clorith.
Fixes #42240.

Note: See TracTickets for help on using tickets.