#35426 closed defect (bug) (fixed)
Create response status code aliases on WP_Http for convenience
Reported by: | joehoyle | Owned by: | joehoyle |
---|---|---|---|
Milestone: | 4.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | HTTP API | Keywords: | has-unit-tests has-patch 2nd-opinion |
Focuses: | Cc: |
Description
Throughout the REST API for response codes, we want to use aliased constants to be more clear in the code for each response code.
The best place to put these constants I think is WP_Http
. This means in the REST API (and any other code) rather than specifying response codes directly (which is terse and opaque) one can use WP_Http::BAD_REQUEST
for example.
Attachments (5)
Change History (16)
#4
@
9 years ago
- Keywords needs-patch needs-unit-tests added
- Resolution fixed deleted
- Status changed from closed to reopened
- Version trunk deleted
The 1xx
statuses are missing.
#6
@
9 years ago
- Keywords has-patch 2nd-opinion added; needs-patch removed
I wonder if these constant names need to be prefixed. CONTINUE
is a reserved word in PHP so can't be used as a constant name.
Better: WP_Http::STATUS_CONTINUE
, WP_Http::STATUS_OK
, etc.
#7
@
9 years ago
@johnbillion That was actually intentional originally (I asked @joehoyle to leave them out), as it's almost impossible for those to get all the way up the stack. Additionally, you should probably never actually send them. They're essentially transactional status codes that are only used to negotiate the connection. 100 Continue i.e. indicates the server is ready to receive the rest of the message, 101 Switching Protocols is used to upgrade protocols (e.g. to HTTP/2). Most of these won't be handled correctly if you send them from WP, and they should never escape the internal handling of WP_HTTP.
That said, we might want them for coverage. If we have conflicts with keywords, I'd prefer we special-case those specific ones rather than all of them.
#8
@
9 years ago
When introduced, they should be used globally, right?
Will it be considered "refactoring just because we can" if these constants was implemented in get_status_header_desc()
?
If not, I can create ticket and patch.
#9
@
9 years ago
@knutsp give that the descriptions already exist in get_status_header_desc
i'm not sure how much value there is to doing that, but I don't feel strongly either way.
@johnbillion I think we'd be better not renaming all constants with STATUS_*
just for CONTINUE
, I'd rather we give 100
a description that isn't a reserved word.
Related #35425