Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6868309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:25:05+00:00 2026-05-27T03:25:05+00:00

Background I’ve been timing some HTTP requests via the CLI using time and tools

  • 0

Background

I’ve been timing some HTTP requests via the CLI using time and tools such as wget and curl as follows:

/usr/bin/time -v wget --spider http://localhost/index
/usr/bin/time -v curl http://localhost/index 2>&1 > /dev/null

What I noticed is that when using curl, I was getting similar response times as with wget only on the first request, and much lower times on subsequent requests, as if the responses to curl were served from cache and wget were not.

After investigating I found out that when specifying --spider, wget issues a HEAD request as appended below which could explain why the cache is bypassed with wget:

Request

HEAD /index HTTP/1.0
User-Agent: Wget/1.12 (linux-gnu)
Accept: */*
Host: localhost
Connection: Keep-Alive

Response

HTTP/1.1 200 OK
Date: Mon, 28 Nov 2011 14:45:59 GMT
Server: Apache/2.2.14 (Ubuntu)
Content-Location: index.php
Vary: negotiate,Accept-Encoding
TCN: choice
X-Powered-By: PHP/5.3.2-1ubuntu4.10
Set-Cookie: SESS421aa90e079fa326b6494f812ad13e79=16oqmug3loekjlb1tlvmsrtcr2; expires=Wed, 21-Dec-2011 18:19:19 GMT; path=/
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Mon, 28 Nov 2011 14:45:59 GMT
Cache-Control: store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8

Since I’m doing more advanced stuff (writing body and headers in separate files, posting data, saving cookie in jar…) I need to use curl instead of wget. Therefore I’m trying to emulate a HEAD request with curl.

Issue

I managed to send a HEAD request with curl as follows:

curl "http://localhost/index" --request "HEAD" -H "Connection: Keep-Alive" -0

Request

HEAD /index HTTP/1.0
User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
Host: localhost
Accept: */*
Connection: Keep-Alive

Response

HTTP/1.1 200 OK
Date: Mon, 28 Nov 2011 15:44:02 GMT
Server: Apache/2.2.14 (Ubuntu)
Content-Location: index.php
Vary: negotiate,Accept-Encoding
TCN: choice
X-Powered-By: PHP/5.3.2-1ubuntu4.10
Set-Cookie: SESS421aa90e079fa326b6494f812ad13e79=4001hcmhdbnkb9e2v8nok9lii1; expires=Wed, 21-Dec-2011 19:17:22 GMT; path=/
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Mon, 28 Nov 2011 15:44:02 GMT
Cache-Control: store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8

Despite the request/response being seemingly OK, when I execute the above curl command while sniffing with tcpdump I can see that the server responds straight away, however my curl command always stays hanging for exactly 15 seconds which is obviously a big issue since I’m trying to time my curl command (FYI before I used to get a curl: (18) transfer closed with 3 bytes remaining to read when the server was not handling HEAD properly and was returning Content-Length: 3 without returning any content, but no everything looks OK).

I tried to play with the --max-time and --speed-time arguments to have curl timeout immediately upon receiving the 200 OK but it makes no difference.

Q: How can I send a HEAD request with curl in a way that the curl command stops immediately upon receiving the response from the server?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:25:06+00:00Added an answer on May 27, 2026 at 3:25 am

    Why don’t you just use the -I option?

    -I/--head
        (HTTP/FTP/FILE) Fetch the HTTP-header only! HTTP-servers feature
        the command HEAD which this uses to get nothing but  the  header
        of  a  document.  When used on a FTP or FILE file, curl displays
        the file size and last modification time only
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: Some time ago, I built a system for recording and categorizing application crashes
BACKGROUND: Co-worker Adam has been using Google refine to process database downloads with much
Background: At my company we are developing a bunch applications that are using the
Background I am writing and using a very simple CGI-based (Perl) content management tool
Background I have been asked by a client to create a picture of the
Background: I have some existing apps in the App Store and I have just
Background: I am using Eclipse to develop an Android app. I have an xml
Background I first wanted to upload a file via json and get a response
Background I've recently been a part of a project where twisted was used. We
Background: This is really a general best-practices question, but some background about the specific

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.