WordPress.org

Make WordPress Core

Opened 14 months ago

Closed 10 months ago

Last modified 9 months ago

#23472 closed enhancement (fixed)

Retrieve the first x bytes of a remote file

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

Description

A commonly useful functionality in HTTP clients is to only request the first x bytes of a document, this can be useful for example, when you only need to fetch the first few KB of a image so as to determine it's dimensions from the initial metadata in the file.

At present, we have no way to offer this through WP_HTTP, The attached patch is a first-scratch effort at adding it. No proper unit tests so far, just casual testing which confirms it working.

Patch

  • Supports all 3 transports
  • Handles streaming-to-file as well
  • Doesn't include Headers in the byte count
  • Works with Redirects

I'll add some Unit tests for this soon hopefully.

Attachments (1)

23472.diff (8.8 KB) - added by dd32 14 months ago.

Download all attachments as: .zip

Change History (9)

dd3214 months ago

comment:1 dd3214 months ago

  • Milestone changed from Awaiting Review to Future Release

Other things of note

  • Disables Compression support (Well, rather it disables WP_HTTP saying it can support compression, servers may still send compressed data.
  • Doesn't work with HTTP 1.1 + Transfer-encoding: Chunked, HTTP 1.1 support is mostly broken at present anyway #23463

comment:2 dd3214 months ago

  • Milestone changed from Future Release to 3.6

comment:3 dd3214 months ago

Throwing this in for some soak time, I've renamed the parameter from 'first-x-bytes' to 'limit-response-size' - I'm not entirely sure of what naming scheme to use for this though, the name may change if someone can suggest a better option.

comment:4 dd3214 months ago

In 23605:

WP_HTTP: Enable developers to request the first x bytes of a document using the 'limit-response-size' parameter.
The connection to the remote server will be disconnected after x number of bytes has been received.
See #23472

comment:5 dd3214 months ago

In 23609:

WP_HTTP: Prevent the 'max_body_length' and 'stream_handle' properties of the curl class from leaking between requests by specifically initializing them in every case. See #23472 & r23605

comment:6 ryan11 months ago

Fixed?

comment:7 dd3210 months ago

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

Lets call it fixed.

comment:8 nacin9 months ago

In 24767:

Rename limit-response-size to limit_response_size. see #23472.

Note: See TracTickets for help on using tickets.