Skip to content

Commit e355a68

Browse files
namedgraphclaude
andcommitted
Enable gzip compression in nginx for RDF and JSON content types (#290)
* Enable gzip compression in nginx for RDF and JSON content types Adds gzip_types covering application/json, SPARQL results, RDF serializations (Turtle, RDF/XML, LD+JSON, TriG, N-Quads, N-Triples), XML, CSS, JS, and SVG. Primarily reduces client.xsl.sef.json transfer size from ~11.8MB to ~2-3MB. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Add gzip HTTP tests for SEF file and RDF/XML response Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix gzip HTTP tests: use -D - to avoid binary body, add owner cert for RDF/XML Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * nginx conf fix * Fix gzip RDF/XML test: create item and append data instead of testing root container Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent cd43ae9 commit e355a68

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,25 @@ configs:
193193
194194
client_max_body_size ${MAX_CONTENT_LENGTH:-2097152};
195195
196+
gzip on;
197+
gzip_proxied any;
198+
gzip_types
199+
application/json
200+
application/ld+json
201+
application/rdf+xml
202+
application/sparql-results+json
203+
application/sparql-results+xml
204+
application/trig
205+
application/n-quads
206+
application/n-triples
207+
application/xml
208+
text/turtle
209+
text/css
210+
text/javascript
211+
application/javascript
212+
image/svg+xml;
213+
gzip_min_length 1024;
214+
196215
# server with optional client cert authentication
197216
server {
198217
listen 8443 ssl;

http-tests/misc/gzip-rdfxml.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
initialize_dataset "$END_USER_BASE_URL" "$TMP_END_USER_DATASET" "$END_USER_ENDPOINT_URL"
5+
initialize_dataset "$ADMIN_BASE_URL" "$TMP_ADMIN_DATASET" "$ADMIN_ENDPOINT_URL"
6+
purge_cache "$END_USER_VARNISH_SERVICE"
7+
purge_cache "$ADMIN_VARNISH_SERVICE"
8+
purge_cache "$FRONTEND_VARNISH_SERVICE"
9+
10+
# Test that nginx gzip compression is active for RDF/XML dynamic content.
11+
# Create an item, append enough data to exceed gzip_min_length, then retrieve it as RDF/XML.
12+
13+
add-agent-to-group.sh \
14+
-f "$OWNER_CERT_FILE" \
15+
-p "$OWNER_CERT_PWD" \
16+
--agent "$AGENT_URI" \
17+
"${ADMIN_BASE_URL}acl/groups/writers/"
18+
19+
item=$(create-item.sh \
20+
-f "$AGENT_CERT_FILE" \
21+
-p "$AGENT_CERT_PWD" \
22+
-b "$END_USER_BASE_URL" \
23+
--title "Gzip test item" \
24+
--slug "gzip-test" \
25+
--container "$END_USER_BASE_URL")
26+
27+
printf '@prefix ex: <http://example.org/> .\n
28+
<> ex:prop1 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore." ;\n
29+
ex:prop2 "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo." ;\n
30+
ex:prop3 "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur." ;\n
31+
ex:prop4 "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est." .\n' \
32+
| post.sh \
33+
-f "$AGENT_CERT_FILE" \
34+
-p "$AGENT_CERT_PWD" \
35+
-t "text/turtle" \
36+
"$item"
37+
38+
response=$(curl -k -s -D - -o /dev/null \
39+
-H "Accept-Encoding: gzip" \
40+
-H "Accept: application/rdf+xml" \
41+
-E "$AGENT_CERT_FILE":"$AGENT_CERT_PWD" \
42+
"$item")
43+
44+
if ! echo "$response" | grep -qi "Content-Encoding: gzip"; then
45+
echo "Content-Encoding: gzip not found on RDF/XML response"
46+
exit 1
47+
fi
48+
49+
if ! echo "$response" | grep -q "HTTP/.* 200"; then
50+
echo "RDF/XML request did not return 200 OK"
51+
exit 1
52+
fi

http-tests/misc/gzip-sefjson.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Test that nginx gzip compression is active for static JSON (SEF file)
5+
6+
response=$(curl -k -s -D - -o /dev/null \
7+
-H "Accept-Encoding: gzip" \
8+
"${END_USER_BASE_URL}static/com/atomgraph/linkeddatahub/xsl/client.xsl.sef.json")
9+
10+
if ! echo "$response" | grep -qi "Content-Encoding: gzip"; then
11+
echo "Content-Encoding: gzip not found on client.xsl.sef.json"
12+
exit 1
13+
fi
14+
15+
if ! echo "$response" | grep -q "HTTP/.* 200"; then
16+
echo "client.xsl.sef.json did not return 200 OK"
17+
exit 1
18+
fi

0 commit comments

Comments
 (0)