ColdFusion - How to limit data received through CFHTTP?

I use cfhttp to get documents and analyze content as follows:

 <cfhttp method="GET" url="#url.strURL#" resolveurl="true" useragent="#CGI.http_user_agent#" result="objGet" timeout="60" charset="utf-8" /> 

However, some of the documents are quite large. I don’t need to do all this - it can take a lot of time.

Is it possible to stop cfhttp from cfhttp after the X number of bytes loaded? Or set a limit on how much you can get, for example.

Rate the help.

+4
source share
1 answer

If the target server supports it, you can use Range http header :

 <cfhttp method="GET" url="#url.strURL#" resolveurl="true" useragent="#CGI.http_user_agent#" result="objGet" timeout="60" charset="utf-8"/> <cfhttpparam type="header" name="Range" value="bytes=0-499" /> </cfhttp> 

Apache and IIS support this, so for static content you are probably lucky. Dynamic content will be harder ...

... I just tried this when CFM was served through Apache and it looks like it did not work. I suspect that if Apache / IIS is serving a static file, it can safely send back a range of bytes from the requested document, since it can read the file. If a request for something is generated by CF / ASP / JSP / regardless, then it will be before Appliation to honor the Range: header in the request. In my case, I still got the whole document because my application is not looking at the Range header.

I should also mention that you can do what you need in Java, since you have finer control over what happens, but you have to write something yourself or use one of the alternative HTTP Client Libraries. It depends on how important this feature is to you, I suppose. If the documents are seriously large, you may need to use the cfhttp file attribute to avoid getting the entire response in memory, which can lead to crashes.

+4
source

All Articles