Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  test_head_request_no_response_body.js

  Sprache: JAVA
 

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


/*

Test that a response to HEAD method should not have a body.
1. Create a GET request and write the response into cache.
2. Create the second GET request with the same URI and see if the response is
   from cache.
3. Create a HEAD request and test if we got a response with an empty body.

*/


"use strict";

const { HttpServer } = ChromeUtils.importESModule(
  "resource://testing-common/httpd.sys.mjs"
);

const responseContent = "response body";

function test_handler(metadata, response) {
  response.setHeader("Content-Type""text/html"false);
  response.setHeader("Cache-control""max-age=9999"false);
  response.setStatusLine(metadata.httpVersion, 200"OK");
  if (metadata.method != "HEAD") {
    response.bodyOutputStream.write(responseContent, responseContent.length);
  }
}

function make_channel(url, method) {
  let channel = NetUtil.newChannel({
    uri: url,
    loadUsingSystemPrincipal: true,
  }).QueryInterface(Ci.nsIHttpChannel);
  channel.requestMethod = method;
  return channel;
}

async function get_response(channel, fromCache) {
  return new Promise(resolve => {
    channel.asyncOpen(
      new ChannelListener((request, buffer, ctx, isFromCache) => {
        Assert.equal(
          fromCache,
          isFromCache,
          `got response from cache = ${fromCache}`
        );
        resolve(buffer);
      })
    );
  });
}

async function stop_server(httpserver) {
  return new Promise(resolve => {
    httpserver.stop(resolve);
  });
}

add_task(async function () {
  let httpserver = new HttpServer();
  httpserver.registerPathHandler("/testdir", test_handler);
  httpserver.start(-1);
  const PORT = httpserver.identity.primaryPort;
  const URI = `http://localhost:${PORT}/testdir`;

  let response;

  response = await get_response(make_channel(URI, "GET"), false);
  Assert.strictEqual(response, responseContent, "got response body");

  response = await get_response(make_channel(URI, "GET"), true);
  Assert.strictEqual(response, responseContent, "got response body from cache");

  response = await get_response(make_channel(URI, "HEAD"), false);
  Assert.strictEqual(response, """should have empty body");

  await stop_server(httpserver);
});

Messung V0.5 in Prozent
C=92 H=87 G=89

¤ Dauer der Verarbeitung: 0.13 Sekunden  (vorverarbeitet am  2026-06-06) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik