function test_encode_request() {
let bhttp = Cc["@mozilla.org/network/binary-http;1"].getService(
Ci.nsIBinaryHttp
);
let request = new BinaryHttpRequest( "GET", "https", "", "/hello.txt",
["user-agent", "host", "accept-language"],
[ "curl/7.16.3 libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3", "www.example.com", "en, mi",
],
[]
);
let encoded = bhttp.encodeRequest(request); // This example is from RFC 9292.
let expected = hexStringToBytes( "0003474554056874747073000a2f6865" + "6c6c6f2e747874406c0a757365722d61" + "67656e74346375726c2f372e31362e33" + "206c69626375726c2f372e31362e3320" + "4f70656e53534c2f302e392e376c207a" + "6c69622f312e322e3304686f73740f77" + "77772e6578616d706c652e636f6d0f61" + "63636570742d6c616e67756167650665" + "6e2c206d690000"
);
deepEqual(encoded, expected);
let mismatchedHeaders = new BinaryHttpRequest( "GET", "https", "", "",
["whoops-only-one-header-name"],
["some-header-value", "some-other-header-value"],
[]
); // The implementation uses "NS_ERROR_INVALID_ARG", because that's an // appropriate description for the error. However, that is an alias to // "NS_ERROR_ILLEGAL_VALUE", which is what the actual exception uses, so // that's what is tested for here. Assert.throws(
() => bhttp.encodeRequest(mismatchedHeaders),
/NS_ERROR_ILLEGAL_VALUE/
);
}
function test_decode_request() {
let bhttp = Cc["@mozilla.org/network/binary-http;1"].getService(
Ci.nsIBinaryHttp
);
function test_encode_response() {
let response = new BinaryHttpResponse(
418,
["content-type"],
["text/plain"],
stringToBytes("I'm a teapot")
);
let bhttp = Cc["@mozilla.org/network/binary-http;1"].getService(
Ci.nsIBinaryHttp
);
let encoded = bhttp.encodeResponse(response);
let expected = hexStringToBytes( "0141a2180c636f6e74656e742d747970650a746578742f706c61696e0c49276d206120746561706f7400"
);
deepEqual(encoded, expected);
let mismatchedHeaders = new BinaryHttpResponse(
500,
["some-header", "some-other-header"],
["whoops-only-one-header-value"],
[]
); // The implementation uses "NS_ERROR_INVALID_ARG", because that's an // appropriate description for the error. However, that is an alias to // "NS_ERROR_ILLEGAL_VALUE", which is what the actual exception uses, so // that's what is tested for here. Assert.throws(
() => bhttp.encodeResponse(mismatchedHeaders),
/NS_ERROR_ILLEGAL_VALUE/
);
}
function run_test() {
test_encode_request();
test_decode_request();
test_encode_response();
test_decode_response();
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
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.