Skip to main content


Closes a synchronous HTTP stream




Table — the decoded response from the remote server


This methods completes the HTTP streaming request and waits for the server’s response. It should be called only when the entire request body has been sent. The call blocks until the full response has been received from the server. If this is undesirable behavior, you should use httpstream.closeasync().

Any attempt to send data to a cancelled or closed stream, including one which has received an error from the server, will cause a Squirrel error.

The returned table has the same fields as the one returned by httprequest.sendsync():

Key Type Description
statuscode Integer HTTP status code (or libcurl error code)
headers Table Squirrel table of returned HTTP headers
body String Returned HTTP body (if any)


If the value of statuscode is 100 or higher, it is a real HTTP status code returned from the server; if it is between 0 and 99, there was an error sending the request.

As an aid to debugging, the 0-99 errors are currently the same as libcurl error messages. For instance, statuscode == 3 means that the URL was malformed, and statuscode == 6 means that the hostname wouldn’t resolve. However, this may change in the future, so don’t write agent code that depends on particular values having particular meanings.

You should note that if an error code is generated, you may still get data back — it will be placed in the body field.


For ease of access from Squirrel, all headers in the headers table are presented in lower case, even if they were received in upper case. According to the RFC2616 specification, headers are case-insensitive.

Example Code

The agent code below uses httpstream.closesync() to terminate the data stream established in the function initiateStream() after 500 data points have been transmitted. The example is simple, so no other operations are in progress while closing the stream takes place. Were that not the case, we could use httpstream.closeasync() to close the stream in the background.