RejectedSoftware Forums

Sign up

HTTP client

How to read only headers from remote host and immediately drop connection?
Is vibe.http.client.requestHTTP suitable for this or it always reads whole body?

Re: HTTP client

Am 30.08.2013 21:24, schrieb Jack Applegame:

How to read only headers from remote host and immediately drop connection?
Is vibe.http.client.requestHTTP suitable for this or it always reads whole body?

The standard conformant way to do this would be to send a HEAD request
instead of a GET one (doesn't work for POST etc. though). But right now
requestHTTP will indeed always read the whole body if the user code
didn't already do so (so that it can keep the connection open).

A HTTPClientResponse.disconnect method would be easy to add and should
do the job.

Re: HTTP client

On Sat, 31 Aug 2013 08:59:02 +0200, Sönke Ludwig wrote:

Am 30.08.2013 21:24, schrieb Jack Applegame:

How to read only headers from remote host and immediately drop connection?
Is vibe.http.client.requestHTTP suitable for this or it always reads whole body?

The standard conformant way to do this would be to send a HEAD request
instead of a GET one (doesn't work for POST etc. though). But right now
requestHTTP will indeed always read the whole body if the user code
didn't already do so (so that it can keep the connection open).

A HTTPClientResponse.disconnect method would be easy to add and should
do the job.

Okay, https://github.com/rejectedsoftware/vibe.d/commit/e1d70e57ad70bf20e4038919999628f5f613b2d4 adds this. I didn't test it, but hopefully there shouldn't be much room for bugs.

Re: HTTP client

On Sat, 31 Aug 2013 08:59:02 +0200, Sönke Ludwig wrote:

The standard conformant way to do this would be to send a HEAD request
instead of a GET one.

Yes, I know. But sometimes (in particular, in my case) remote host doesn't support HEAD requests. GET responses with Last-Modified header and large body. Body is being cached on local host.

On Sat, 31 Aug 2013 07:23:52 GMT, Sönke Ludwig wrote:

On Sat, 31 Aug 2013 08:59:02 +0200, Sönke Ludwig wrote:

A HTTPClientResponse.disconnect method would be easy to add and should
do the job.

Okay, https://github.com/rejectedsoftware/vibe.d/commit/e1d70e57ad70bf20e4038919999628f5f613b2d4 adds this. I didn't test it, but hopefully there shouldn't be much room for bugs.

I tested it and everything works. Thanks, I really needed it.

Re: HTTP client

Am 31.08.2013 11:40, schrieb Jack Applegame:

On Sat, 31 Aug 2013 08:59:02 +0200, Sönke Ludwig wrote:

The standard conformant way to do this would be to send a HEAD request
instead of a GET one.
Yes, I know. But sometimes (in particular, in my case) remote host doesn't support HEAD requests. GET responses with Last-Modified header and large body. Body is being cached on local host.

Is the "If-Modified-Since" header supported maybe? Or "If-None-Match"
with an Etag instead of a last modified date?

Re: HTTP client

On Sat, 31 Aug 2013 11:47:35 +0200, Sönke Ludwig wrote:

Is the "If-Modified-Since" header supported maybe? Or "If-None-Match"
with an Etag instead of a last modified date?

Wow! You're right. If-Modified-Since works. It was foolish of me not to check this possibility. Shame.

Another question. Is there a simple way to convert HTTP date/time strings from/to SysTime?

Re: HTTP client

Am 31.08.2013 12:30, schrieb Jack Applegame:

On Sat, 31 Aug 2013 11:47:35 +0200, Sönke Ludwig wrote:

Is the "If-Modified-Since" header supported maybe? Or "If-None-Match"
with an Etag instead of a last modified date?

Wow! You're right. If-Modified-Since works. It was foolish of me not to check this possibility. Shame.

Another question. Is there a simple way to convert HTTP date/time strings from/to SysTime?

Yes, there are a couple of functions in vibe.inet.message (e.g.
parseRFC822DateTimeString) that work with the format used for HTTP and
other protocols.

Re: HTTP client

Very good.