Skip to content

Commit

Permalink
CHANGE: use the standardized br instead of brotli as the compress…
Browse files Browse the repository at this point in the history
…ion method name
  • Loading branch information
Oldes committed Jul 12, 2024
1 parent 541cc51 commit fc55543
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/core/b-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** REBOL [R3] Language Interpreter and Run-time Environment
**
** Copyright 2012 REBOL Technologies
** Copyright 2012-2023 Rebol Open Source Contributors
** Copyright 2012-2024 Rebol Open Source Contributors
** REBOL is a trademark of REBOL Technologies
**
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -1009,7 +1009,7 @@ static void Set_Option_File(REBCNT field, REBYTE* src, REBOOL dir )
blk = Get_System(SYS_CATALOG, CAT_COMPRESSIONS);
if (blk && IS_BLOCK(blk)) {
#ifdef INCLUDE_BROTLI
add_compression(SYM_BROTLI);
add_compression(SYM_BR);
#endif
#ifdef INCLUDE_CRUSH
add_compression(SYM_CRUSH);
Expand Down
4 changes: 2 additions & 2 deletions src/core/n-strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ static struct digest {
windowBits |= 16;
goto zlib_compress;

case SYM_BROTLI:
case SYM_BR:
#ifdef INCLUDE_BROTLI
Set_Binary(D_RET, CompressBrotli(ser, index, (REBINT)len, ref_level ? VAL_INT32(level) : -1));
#else
Expand Down Expand Up @@ -507,7 +507,7 @@ static struct digest {
windowBits |= 16;
goto zlib_decompress;

case SYM_BROTLI:
case SYM_BR:
#ifdef INCLUDE_BROTLI
Set_Binary(D_RET, DecompressBrotli(VAL_SERIES(data), VAL_INDEX(data), (REBINT)len, limit));
#else
Expand Down
13 changes: 6 additions & 7 deletions src/mezz/prot-http.reb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ REBOL [
Licensed under the Apache License, Version 2.0
See: http://www.apache.org/licenses/LICENSE-2.0
}
Version: 0.5.3
Date: 11-Jul-2024
Version: 0.5.4
Date: 12-Jul-2024
File: %prot-http.r3
Purpose: {
This program defines the HTTP protocol scheme for REBOL 3.
Expand Down Expand Up @@ -679,11 +679,10 @@ decode-result: func[
result [block!] {[header body]}
/local body content-type code-page encoding
][
if encoding: select result/2 'Content-Encoding [
either find ["gzip" "deflate" "br"] encoding [
if encoding == "br" [encoding: 'brotli]
if encoding: attempt [to word! result/2/Content-Encoding] [
either find system/catalog/compressions encoding [
try/with [
result/3: decompress result/3 to word! encoding
result/3: decompress result/3 encoding
][
sys/log/info 'HTTP ["Failed to decode data using:^[[22m" encoding]
return result
Expand Down Expand Up @@ -964,7 +963,7 @@ sys/make-scheme [
;@@ One can set above value for example to: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
;@@ And so pretend that request is coming from Chrome on Windows10
]
if find system/catalog/compressions 'brotli [
if find system/catalog/compressions 'br [
append headers/Accept-Encoding ",br"
]
]
Expand Down
44 changes: 22 additions & 22 deletions src/tests/units/compress-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -124,41 +124,41 @@ text: {Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempo

===start-group=== "Brotli compression / decompression"
--test-- "Brotli compress/decompress"
either error? e: try [compress "test" 'brotli][
either error? e: try [compress "test" 'br][
;-- Brotli compression is not available in current build
--assert 'feature-na = e/id
][
--assert data = to string! decompress compress data 'brotli 'brotli
--assert data = to string! decompress compress data 'br 'br

--test-- "Brotli compress/decompress while specifing level of compression"
--assert (compress/level "" 'brotli 0) =
--assert (compress/level "" 'br 0) =
#{3B}
--assert (compress/level data 'brotli 0) =
--assert (compress/level data 'br 0) =
#{8B0680746573742074657374207465737403}
--assert text = to string! decompress compress/level text 'brotli 0 'brotli
--assert text = to string! decompress compress/level text 'brotli 1 'brotli
--assert text = to string! decompress compress/level text 'brotli 2 'brotli
--assert text = to string! decompress compress/level text 'brotli 3 'brotli
--assert text = to string! decompress compress/level text 'brotli 4 'brotli
--assert text = to string! decompress compress/level text 'brotli 5 'brotli
--assert text = to string! decompress compress/level text 'brotli 6 'brotli
--assert text = to string! decompress compress/level text 'brotli 7 'brotli
--assert text = to string! decompress compress/level text 'brotli 8 'brotli
--assert text = to string! decompress compress/level text 'brotli 9 'brotli
--assert text = to string! decompress compress/level text 'brotli 10 'brotli
--assert text = to string! decompress compress/level text 'brotli 11 'brotli
--assert text = to string! decompress compress/level text 'br 0 'br
--assert text = to string! decompress compress/level text 'br 1 'br
--assert text = to string! decompress compress/level text 'br 2 'br
--assert text = to string! decompress compress/level text 'br 3 'br
--assert text = to string! decompress compress/level text 'br 4 'br
--assert text = to string! decompress compress/level text 'br 5 'br
--assert text = to string! decompress compress/level text 'br 6 'br
--assert text = to string! decompress compress/level text 'br 7 'br
--assert text = to string! decompress compress/level text 'br 8 'br
--assert text = to string! decompress compress/level text 'br 9 'br
--assert text = to string! decompress compress/level text 'br 10 'br
--assert text = to string! decompress compress/level text 'br 11 'br

--test-- "Brotli decompression with specified uncompressed size"
bin: compress data 'brotli
--assert #{74657374} = decompress/size bin 'brotli 4
bin: compress data 'br
--assert #{74657374} = decompress/size bin 'br 4

--test-- "Brotli compression when input is limited"
--assert #{74657374} = decompress compress/part data 'brotli 4 'brotli
--assert #{74657374} = decompress compress/part skip data 5 'brotli 4 'brotli
--assert #{74657374} = decompress compress/part tail data 'brotli -4 'brotli
--assert #{74657374} = decompress compress/part data 'br 4 'br
--assert #{74657374} = decompress compress/part skip data 5 'br 4 'br
--assert #{74657374} = decompress compress/part tail data 'br -4 'br

--test-- "Brotli decompress when not at head"
--assert data = to string! decompress next join #{00} compress data 'brotli 'brotli
--assert data = to string! decompress next join #{00} compress data 'br 'br
]
===end-group===

Expand Down

0 comments on commit fc55543

Please sign in to comment.