I'm using Dispatch to pull down a lot of pages from which I only need the first few K, and the pages are sometimes gigabytes. Is there any way in scala-dispatch (dispatch/reboot), or maybe in the HTTP request, to truncate the body received?
(Context: I'm reading CSV files from public data sources, and am just trying to get the field names (header row) and one row of sample data.)
You can using the
>handler, which gives you access to the underlyingcom.ning.http.client.Responseinstance. From there, it's simple:You might also try to request a smaller byte interval from the server using the
Rangeheader. This requires server support, which can be tested using aHEADrequest and then looking up theAccept-Ranges: bytesresponse header.