How to use the head function from request

Find comprehensive JavaScript request.head code examples handpicked from public code repositorys.

request.head is a function in the Request library that sends an HTTP HEAD request to a server and returns a response.

103
104
105
106
107
108
109
110
111
112
113


// Download function with progress bar 
let progressBar
const download = (uri, filename, callback) => {
  // HEAD request first
  request.head(uri, (err, res, body) => {
      if (res.statusCode != 404) {
        let receivedBytes = 0
        const totalBytes = res.headers['content-length']
        logger.info(`Total size to download: ${totalBytes}`)
fork icon225
star icon729
watch icon32

+ 5 other calls in file

215
216
217
218
219
220
221
222
223
224
                
//sticker url
const sendStickerFromUrl = async(to, url) => {
                var names = Date.now() / 10000;
                var download = function (uri, filename, callback) {
                    request.head(uri, function (err, res, body) {
                        request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
                    });
                };
                download(url, './database/stick' + names + '.png', async function () {
fork icon38
star icon19
watch icon1

+ 3 other calls in file

How does request.head work?

request.head is a method in the request library for making a HEAD HTTP request to a specified URL, which is useful for fetching metadata about a resource without downloading its entire contents. The method sends a request to the URL with the specified options, including headers, query parameters, and authentication details, and returns a stream of the response metadata.

208
209
210
211
212
213
214
215
216
217
              const mentionUser = mention != undefined ? mention.filter(n => n) : []
              
const sendStickerFromUrl = async (to, url) => {
    var names = Date.now() / 10000;
    var download = function (uri, filename, callback) {
      request.head(uri, function (err, res, chats) {
        request(uri)
          .pipe(fs.createWriteStream(filename))
          .on("close", callback);
      });
fork icon1
star icon0
watch icon0

+ 2 other calls in file

1652
1653
1654
1655
1656
1657
1658
1659
1660
1661

//                 try {
//                     const mJRE = data[Library.mojangFriendlyOS()]['64'].jre
//                     const url = mJRE.url

//                     request.head(url, (err, resp, body) => {
//                         if(err){
//                             resolve(false)
//                         } else {
//                             const name = url.substring(url.lastIndexOf('/')+1)
fork icon0
star icon1
watch icon0

+ 195 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
const request = require("request");

request.head("https://www.example.com", function (error, response, body) {
  if (!error && response.statusCode === 200) {
    console.log("The server supports the HEAD method.");
  } else {
    console.log("The server does not support the HEAD method.");
  }
});

This code sends a HEAD request to https://www.example.com and logs a message indicating whether or not the server supports the HEAD method.

5
6
7
8
9
10
11
12
13
14
15
const request = require('request')
const vuri = require('valid-url');
const fs = require('fs');


const mediadownloader = (url, path, callback) => {
    request.head(url, (err, res, body) => {
        request(url)
            .pipe(fs.createWriteStream(path))
            .on('close', callback)
    })
fork icon1
star icon0
watch icon1

6
7
8
9
10
11
12
13
14
15
16


Base.prototype.salvar = function(callback){
    var data = this;
    var restName = this.restName;
    var baseHost = this.baseHost;
    request.head(baseHost + "/" + restName + ".json", function(){
        token = this.response.headers.auth_token;
        if(data.id === "" || data.id === undefined || data.id === 0 ){
            request.post({ 
                url: baseHost + "/" + restName + ".json", 
fork icon3
star icon0
watch icon1

+ 11 other calls in file

241
242
243
244
245
246
247
248
249
250
  problems.push(url);
  linkTimer = null;
  wrapUpLinkValidate(i, problems);
}, 4000);

requestModule.head(url, function (error, resp) {
  if (linkTimer !== null) { // otherwise, the timer already went off and this link has already been marked as bad, so do nothing
    clearTimeout(linkTimer);
    if (error || !resp || !resp.statusCode) {
      problems.push(url);
fork icon1
star icon1
watch icon2

173
174
175
176
177
178
179
180
181
182
183
const maker = require('Open-APIs');
const hx = require('RiczXD-clone');


var creator = creatorList[Math.floor(Math.random() * creatorList.length)];
var download = function(uri, filename, callback) {
    request.head(uri, function(err, res, body) {
        console.log('content-type:', res.headers['content-type']);
        request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
    });
};
fork icon0
star icon0
watch icon1

+ 2 other calls in file

188
189
190
191
192
193
194
195
196
197
198
199
200




var download = function(uri, filename, callback){
    let pathToImageMenu;
  uri = pathToImageMenu;
    request.head(uri, function(err, res, body){
      //  console.log('content-type:', res.headers['content-type']);
     //   console.log('content-length:', res.headers['content-length']);


        request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
fork icon0
star icon0
watch icon0

59
60
61
62
63
64
65
66
67
68
69
70


function download_n_build() {
  try {
    allBricks = [] // Resetting before downloading & building


    request.head(`https://docs.google.com/spreadsheets/d/${google_sheet_id}/export?format=xlsx`, function(err, res, body) {
      request(`https://docs.google.com/spreadsheets/d/${google_sheet_id}/export?format=xlsx`)
      .pipe(fs.createWriteStream("Data/database.xlsx"))
      .on('close', () => { buildWebsite() }) // When its done downloading file build website
    })
fork icon0
star icon0
watch icon0