From c7e4f2d2328d36baa19f3986b4b88606741ecc1f Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Tue, 2 May 2023 00:38:02 -0400 Subject: [PATCH 01/11] python script to generate a .json.gz file per each locale --- .gitignore | 1 + scripts/update-gz.py | 61 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 scripts/update-gz.py diff --git a/.gitignore b/.gitignore index 4790724..a1e7c7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ schema.json.gz +locales/ diff --git a/scripts/update-gz.py b/scripts/update-gz.py new file mode 100644 index 0000000..3806c3d --- /dev/null +++ b/scripts/update-gz.py @@ -0,0 +1,61 @@ +import os +import shutil +import gzip +import json +import sys +from pathlib import Path +import copy + +parent_folder = Path(__file__).resolve().parent.parent +gzipped_file = f'{parent_folder}/schema.json.gz' +schema_file = f'{parent_folder}/schema.json' + +with open(schema_file, 'r') as f: + schema_text = f.read() + schema = json.loads(schema_text) + +if not os.path.exists('../locales'): + os.mkdir('../locales') + +# For each item in the 'locales' list of the schema +for locale_name in schema['locales'].keys(): + locale_file_name = f"{locale_name}.json.gz" + schema_with_one_locale = copy.deepcopy(schema) + current_locale = schema_with_one_locale['locales'][locale_name] + + # If --sub argument is passed, substitute field names for ones from the corresponding locale + if len(sys.argv) == 2 and sys.argv[1] == '--sub': + for item_type in schema_with_one_locale['itemTypes']: + if item_type['itemType'] in current_locale["itemTypes"]: + item_type['itemType'] = current_locale["itemTypes"][item_type['itemType']] + for field in item_type['fields']: + if field['field'] in current_locale["itemTypes"]: + field['field'] = current_locale["itemTypes"][field['field']] + for creator_type in item_type['creatorTypes']: + if creator_type['creatorType'] in current_locale["itemTypes"]: + creator_type['creatorType'] = current_locale["itemTypes"][creator_type['creatorType']] + del schema_with_one_locale['locales'] + + else: + # otherwise, just keep the relevant locale in the same schema + schema_with_one_locale['locales'] = {locale_name : current_locale} + + # generate a gzip file and save it to the locales subdirectory + with gzip.open('../locales/' + locale_file_name, 'wb') as f_out: + json_bytes = json.dumps(schema_with_one_locale, ensure_ascii=False).encode('utf8') + f_out.write(json_bytes) + + +# Check if the gzip file exists, create it if not +if not os.path.exists(gzipped_file): + with open(schema_file, 'rb') as f_in, gzip.open(gzipped_file, 'wb') as f_out: + shutil.copyfileobj(f_in, f_out) + +with gzip.open(gzipped_file, mode='r') as f: + gzip_schema = f.read() + +# # Compare the json of gzip file with the current schema json +if json.dumps(json.loads(gzip_schema)) != json.dumps(json.loads(schema_text)): + print(f'{gzipped_file} updated') +else: + print('Schema hasn\'t changed') From def1906c1470788c5fd111de4bd6d03a6d6399d8 Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Tue, 2 May 2023 00:51:19 -0400 Subject: [PATCH 02/11] typo fix --- scripts/update-gz.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/scripts/update-gz.py b/scripts/update-gz.py index 3806c3d..f14f0b7 100644 --- a/scripts/update-gz.py +++ b/scripts/update-gz.py @@ -46,16 +46,6 @@ f_out.write(json_bytes) -# Check if the gzip file exists, create it if not -if not os.path.exists(gzipped_file): - with open(schema_file, 'rb') as f_in, gzip.open(gzipped_file, 'wb') as f_out: - shutil.copyfileobj(f_in, f_out) - -with gzip.open(gzipped_file, mode='r') as f: - gzip_schema = f.read() - -# # Compare the json of gzip file with the current schema json -if json.dumps(json.loads(gzip_schema)) != json.dumps(json.loads(schema_text)): - print(f'{gzipped_file} updated') -else: - print('Schema hasn\'t changed') +# Create gzip for the main schema +with open(schema_file, 'rb') as f_in, gzip.open(gzipped_file, 'wb') as f_out: + shutil.copyfileobj(f_in, f_out) From d15f816e90e748ea5f96b1d34dfb9e8957e36fd2 Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Tue, 2 May 2023 11:23:42 -0400 Subject: [PATCH 03/11] generating .htaccess file + cleanup --- scripts/update-gz.py | 59 ++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/scripts/update-gz.py b/scripts/update-gz.py index f14f0b7..1d7b6d3 100644 --- a/scripts/update-gz.py +++ b/scripts/update-gz.py @@ -2,50 +2,67 @@ import shutil import gzip import json -import sys from pathlib import Path import copy parent_folder = Path(__file__).resolve().parent.parent gzipped_file = f'{parent_folder}/schema.json.gz' schema_file = f'{parent_folder}/schema.json' +locales_folder = f'{parent_folder}/locales' with open(schema_file, 'r') as f: schema_text = f.read() schema = json.loads(schema_text) -if not os.path.exists('../locales'): - os.mkdir('../locales') +if os.path.exists(locales_folder): + shutil.rmtree(locales_folder) + +os.mkdir(locales_folder) + +# String that accumulates the rules to paste into htaccess +htaccess_rules = f"RewriteRule ^schema/({'|'.join(schema['locales'].keys())})$ /zotero-schema/locales/$1.gz [L]" +#Dict to collect country codes with locales to handle multiple locales per country code +htaccess_mapings = {} # For each item in the 'locales' list of the schema for locale_name in schema['locales'].keys(): - locale_file_name = f"{locale_name}.json.gz" schema_with_one_locale = copy.deepcopy(schema) current_locale = schema_with_one_locale['locales'][locale_name] - # If --sub argument is passed, substitute field names for ones from the corresponding locale - if len(sys.argv) == 2 and sys.argv[1] == '--sub': - for item_type in schema_with_one_locale['itemTypes']: - if item_type['itemType'] in current_locale["itemTypes"]: - item_type['itemType'] = current_locale["itemTypes"][item_type['itemType']] - for field in item_type['fields']: - if field['field'] in current_locale["itemTypes"]: - field['field'] = current_locale["itemTypes"][field['field']] - for creator_type in item_type['creatorTypes']: - if creator_type['creatorType'] in current_locale["itemTypes"]: - creator_type['creatorType'] = current_locale["itemTypes"][creator_type['creatorType']] - del schema_with_one_locale['locales'] - + schema_with_one_locale['locales'] = {locale_name : current_locale} + + # Rule to match by country + if locale_name[:2] in htaccess_mapings: + htaccess_mapings[locale_name[:2]].append(locale_name) else: - # otherwise, just keep the relevant locale in the same schema - schema_with_one_locale['locales'] = {locale_name : current_locale} - + htaccess_mapings[locale_name[:2]] = [locale_name] + # generate a gzip file and save it to the locales subdirectory - with gzip.open('../locales/' + locale_file_name, 'wb') as f_out: + with gzip.open(f'{locales_folder}/{locale_name}.json.gz', 'wb') as f_out: json_bytes = json.dumps(schema_with_one_locale, ensure_ascii=False).encode('utf8') f_out.write(json_bytes) +def locale_sort_key(a): + # Prefer en-US + if a == 'en-US': + return 'A' + # Prefer canonical locales + if a[:2] == a[3:5].lower(): + return 'A' + return a[3:5] + +# For every country code, sort locale candidates and add rule to htacecss +for country_code in htaccess_mapings.keys(): + htaccess_mapings[country_code].sort(key=locale_sort_key) + htaccess_rules += f'\nRewriteRule ^schema/{country_code} /zotero-schema/locales/{htaccess_mapings[country_code][0]}.gz [L]' + +# Catch all for default schema with all locales +htaccess_rules += f'\nRewriteRule ^schema/* /zotero-schema/schema.json.gz [L]' + +print("--- .htacess rules --- \n" + htaccess_rules + "\n--- ---") + + # Create gzip for the main schema with open(schema_file, 'rb') as f_in, gzip.open(gzipped_file, 'wb') as f_out: shutil.copyfileobj(f_in, f_out) From 962f3c33b3299da91cf1972f3e4577227fad83cf Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Tue, 2 May 2023 16:23:11 -0400 Subject: [PATCH 04/11] slightly refined htaccess rules --- scripts/update-gz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update-gz.py b/scripts/update-gz.py index 1d7b6d3..f66a009 100644 --- a/scripts/update-gz.py +++ b/scripts/update-gz.py @@ -55,7 +55,7 @@ def locale_sort_key(a): # For every country code, sort locale candidates and add rule to htacecss for country_code in htaccess_mapings.keys(): htaccess_mapings[country_code].sort(key=locale_sort_key) - htaccess_rules += f'\nRewriteRule ^schema/{country_code} /zotero-schema/locales/{htaccess_mapings[country_code][0]}.gz [L]' + htaccess_rules += f'\nRewriteRule ^schema/{country_code}(-.*)?$ /zotero-schema/locales/{htaccess_mapings[country_code][0]}.gz [L]' # Catch all for default schema with all locales htaccess_rules += f'\nRewriteRule ^schema/* /zotero-schema/schema.json.gz [L]' From 31e232e657dd8c1b74a9957441d8e74d122efadb Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Wed, 3 May 2023 10:58:30 -0400 Subject: [PATCH 05/11] htaccess rules with locale as query parameter instead of path --- scripts/update-gz.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/update-gz.py b/scripts/update-gz.py index f66a009..1ac4ab7 100644 --- a/scripts/update-gz.py +++ b/scripts/update-gz.py @@ -20,7 +20,9 @@ os.mkdir(locales_folder) # String that accumulates the rules to paste into htaccess -htaccess_rules = f"RewriteRule ^schema/({'|'.join(schema['locales'].keys())})$ /zotero-schema/locales/$1.gz [L]" +htaccess_rules = f'''RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({'|'.join(schema['locales'].keys())})(?:&|$) +RewriteRule ^schema(/.*)?$ /zotero-schema/locales/%1.json.gz [L,QSD] +''' #Dict to collect country codes with locales to handle multiple locales per country code htaccess_mapings = {} @@ -52,15 +54,19 @@ def locale_sort_key(a): return 'A' return a[3:5] + # For every country code, sort locale candidates and add rule to htacecss for country_code in htaccess_mapings.keys(): htaccess_mapings[country_code].sort(key=locale_sort_key) - htaccess_rules += f'\nRewriteRule ^schema/{country_code}(-.*)?$ /zotero-schema/locales/{htaccess_mapings[country_code][0]}.gz [L]' + htaccess_rules += f''' +RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({country_code}(-.*)?)(?:&|$) +RewriteRule ^schema(/.*)?$ /zotero-schema/locales/{htaccess_mapings[country_code][0]}.gz [L,QSD] +''' # Catch all for default schema with all locales -htaccess_rules += f'\nRewriteRule ^schema/* /zotero-schema/schema.json.gz [L]' +htaccess_rules += f'\nRewriteRule ^schema$ /zotero-schema/schema.json.gz [L,QSD]' -print("--- .htacess rules --- \n" + htaccess_rules + "\n--- ---") +print(htaccess_rules) # Create gzip for the main schema From b90db185828db33daf859570ebe3fcabfabe77a6 Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Thu, 4 May 2023 11:00:17 -0400 Subject: [PATCH 06/11] defaulting to schema.json if gzip is not accepted, rules to serve correct content type, and filematch --- scripts/update-gz | 103 ++++++++++++++++++++++++++++++++++++------- scripts/update-gz.py | 74 ------------------------------- 2 files changed, 88 insertions(+), 89 deletions(-) delete mode 100644 scripts/update-gz.py diff --git a/scripts/update-gz b/scripts/update-gz index 6a8306f..602907d 100755 --- a/scripts/update-gz +++ b/scripts/update-gz @@ -1,19 +1,92 @@ -#!/bin/bash +#!/usr/bin/python3 +import os +import shutil +import gzip +import json +from pathlib import Path +import copy -dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -cd $dir/.. +parent_folder = Path(__file__).resolve().parent.parent +gzipped_file = f'{parent_folder}/schema.json.gz' +schema_file = f'{parent_folder}/schema.json' +locales_folder = f'{parent_folder}/locales' -file=schema.json.gz -tmp_file=$file-tmp +with open(schema_file, 'r') as f: + schema_text = f.read() + schema = json.loads(schema_text) -gzip -c schema.json > $tmp_file +if os.path.exists(locales_folder): + shutil.rmtree(locales_folder) -DIFF=$(diff $file $tmp_file) -if [ "$DIFF" != "" ] -then - echo "$file updated" - mv $tmp_file $file -else - echo "Schema hasn't changed" - rm $tmp_file -fi +os.mkdir(locales_folder) + +# Begin by checking if gzip is supported. If not - return schema.json +htaccess_rules = f'''RewriteCond %{{HTTP:Accept-Encoding}} !gzip +RewriteRule ^schema(/.*)?$ /zotero-schema/schema.json [QSD,L] +RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({'|'.join(schema['locales'].keys())})(?:&|$) +RewriteRule ^schema(/.*)?$ /zotero-schema/locales/%1.json.gz [QSD] +''' +#Dict to collect country codes with locales to handle multiple locales per country code +htaccess_mapings = {} + +# For each item in the 'locales' list of the schema +for locale_name in schema['locales'].keys(): + schema_with_one_locale = copy.deepcopy(schema) + current_locale = schema_with_one_locale['locales'][locale_name] + + schema_with_one_locale['locales'] = {locale_name : current_locale} + + # Rule to match by country + if locale_name[:2] in htaccess_mapings: + htaccess_mapings[locale_name[:2]].append(locale_name) + else: + htaccess_mapings[locale_name[:2]] = [locale_name] + + # generate a gzip file and save it to the locales subdirectory + with gzip.open(f'{locales_folder}/{locale_name}.json.gz', 'wb') as f_out: + json_bytes = json.dumps(schema_with_one_locale, ensure_ascii=False).encode('utf8') + f_out.write(json_bytes) + + +def locale_sort_key(a): + # Prefer en-US + if a == 'en-US': + return 'A' + # Prefer canonical locales + if a[:2] == a[3:5].lower(): + return 'A' + return a[3:5] + + +# For every country code, sort locale candidates and add rule to htacecss +for country_code in htaccess_mapings.keys(): + htaccess_mapings[country_code].sort(key=locale_sort_key) + # Each rule is only applid is gzip encoding is accepted + htaccess_rules += f'''RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({country_code}(-.*)?)(?:&|$) +RewriteRule ^schema(/.*)?$ /zotero-schema/locales/{htaccess_mapings[country_code][0]}.json.gz [QSD] +''' + +# Catch all for default schema with all locales +htaccess_rules += '''RewriteRule ^schema$ /zotero-schema/schema.json.gz [QSD]''' + +#Rules to serve correct content type and prevent double gzip matching all locales +htaccess_rules += ''' +RewriteRule ^zotero-schema/schema\.json.gz$ - [T=application/json,E=no-gzip:1] +RewriteRule ^zotero-schema/locales/.*\.json.gz$ - [T=application/json,E=no-gzip:1]''' + +htaccess_rules += f''' + + # Serve correct encoding type + Header append Content-Encoding gzip + # Force proxies to cache gzipped & non-gzipped schema file separately + Header append Vary Accept-Encoding + # CORS + Header set Access-Control-Allow-Origin "*" +''' + +print(htaccess_rules) + + +# Create gzip for the main schema +with open(schema_file, 'rb') as f_in, gzip.open(gzipped_file, 'wb') as f_out: + shutil.copyfileobj(f_in, f_out) diff --git a/scripts/update-gz.py b/scripts/update-gz.py deleted file mode 100644 index 1ac4ab7..0000000 --- a/scripts/update-gz.py +++ /dev/null @@ -1,74 +0,0 @@ -import os -import shutil -import gzip -import json -from pathlib import Path -import copy - -parent_folder = Path(__file__).resolve().parent.parent -gzipped_file = f'{parent_folder}/schema.json.gz' -schema_file = f'{parent_folder}/schema.json' -locales_folder = f'{parent_folder}/locales' - -with open(schema_file, 'r') as f: - schema_text = f.read() - schema = json.loads(schema_text) - -if os.path.exists(locales_folder): - shutil.rmtree(locales_folder) - -os.mkdir(locales_folder) - -# String that accumulates the rules to paste into htaccess -htaccess_rules = f'''RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({'|'.join(schema['locales'].keys())})(?:&|$) -RewriteRule ^schema(/.*)?$ /zotero-schema/locales/%1.json.gz [L,QSD] -''' -#Dict to collect country codes with locales to handle multiple locales per country code -htaccess_mapings = {} - -# For each item in the 'locales' list of the schema -for locale_name in schema['locales'].keys(): - schema_with_one_locale = copy.deepcopy(schema) - current_locale = schema_with_one_locale['locales'][locale_name] - - schema_with_one_locale['locales'] = {locale_name : current_locale} - - # Rule to match by country - if locale_name[:2] in htaccess_mapings: - htaccess_mapings[locale_name[:2]].append(locale_name) - else: - htaccess_mapings[locale_name[:2]] = [locale_name] - - # generate a gzip file and save it to the locales subdirectory - with gzip.open(f'{locales_folder}/{locale_name}.json.gz', 'wb') as f_out: - json_bytes = json.dumps(schema_with_one_locale, ensure_ascii=False).encode('utf8') - f_out.write(json_bytes) - - -def locale_sort_key(a): - # Prefer en-US - if a == 'en-US': - return 'A' - # Prefer canonical locales - if a[:2] == a[3:5].lower(): - return 'A' - return a[3:5] - - -# For every country code, sort locale candidates and add rule to htacecss -for country_code in htaccess_mapings.keys(): - htaccess_mapings[country_code].sort(key=locale_sort_key) - htaccess_rules += f''' -RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({country_code}(-.*)?)(?:&|$) -RewriteRule ^schema(/.*)?$ /zotero-schema/locales/{htaccess_mapings[country_code][0]}.gz [L,QSD] -''' - -# Catch all for default schema with all locales -htaccess_rules += f'\nRewriteRule ^schema$ /zotero-schema/schema.json.gz [L,QSD]' - -print(htaccess_rules) - - -# Create gzip for the main schema -with open(schema_file, 'rb') as f_in, gzip.open(gzipped_file, 'wb') as f_out: - shutil.copyfileobj(f_in, f_out) From 498b190d3c9957eb87b007541892c7d18de2e409 Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Thu, 4 May 2023 14:30:51 -0400 Subject: [PATCH 07/11] skipping rules if url does not start with /schema --- scripts/update-gz | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/update-gz b/scripts/update-gz index 602907d..d8e76c7 100755 --- a/scripts/update-gz +++ b/scripts/update-gz @@ -21,7 +21,9 @@ if os.path.exists(locales_folder): os.mkdir(locales_folder) # Begin by checking if gzip is supported. If not - return schema.json -htaccess_rules = f'''RewriteCond %{{HTTP:Accept-Encoding}} !gzip +htaccess_rules = f'''RewriteCond %{{REQUEST_URI}} !^/schema +RewriteRule ".?" "-" [S=LINES_TO_SKIP] +RewriteCond %{{HTTP:Accept-Encoding}} !gzip RewriteRule ^schema(/.*)?$ /zotero-schema/schema.json [QSD,L] RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({'|'.join(schema['locales'].keys())})(?:&|$) RewriteRule ^schema(/.*)?$ /zotero-schema/locales/%1.json.gz [QSD] @@ -84,6 +86,7 @@ htaccess_rules += f''' Header set Access-Control-Allow-Origin "*" ''' +htaccess_rules = htaccess_rules.replace("LINES_TO_SKIP", str(len(htaccess_rules.split('RewriteRule'))-2)) print(htaccess_rules) From 4ccd056b6aab62564524daf274e223efaa9bd43e Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Thu, 4 May 2023 16:11:26 -0400 Subject: [PATCH 08/11] updated filter to not skip rules on zotero-schema --- scripts/update-gz | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update-gz b/scripts/update-gz index d8e76c7..f5c68e8 100755 --- a/scripts/update-gz +++ b/scripts/update-gz @@ -21,7 +21,7 @@ if os.path.exists(locales_folder): os.mkdir(locales_folder) # Begin by checking if gzip is supported. If not - return schema.json -htaccess_rules = f'''RewriteCond %{{REQUEST_URI}} !^/schema +htaccess_rules = f'''RewriteCond %{{REQUEST_URI}} !^/(schema|zotero-schema) RewriteRule ".?" "-" [S=LINES_TO_SKIP] RewriteCond %{{HTTP:Accept-Encoding}} !gzip RewriteRule ^schema(/.*)?$ /zotero-schema/schema.json [QSD,L] From e3e1ed55ed895e7e2312d6101167361c67800311 Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Fri, 5 May 2023 08:22:44 -0400 Subject: [PATCH 09/11] simplifications for the rules --- scripts/update-gz | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/update-gz b/scripts/update-gz index f5c68e8..399fbd7 100755 --- a/scripts/update-gz +++ b/scripts/update-gz @@ -21,8 +21,8 @@ if os.path.exists(locales_folder): os.mkdir(locales_folder) # Begin by checking if gzip is supported. If not - return schema.json -htaccess_rules = f'''RewriteCond %{{REQUEST_URI}} !^/(schema|zotero-schema) -RewriteRule ".?" "-" [S=LINES_TO_SKIP] +htaccess_rules = f'''RewriteCond %{{REQUEST_URI}} !^/schema +RewriteRule ".?" "-" [S=LINES_TO_SKIP,L] RewriteCond %{{HTTP:Accept-Encoding}} !gzip RewriteRule ^schema(/.*)?$ /zotero-schema/schema.json [QSD,L] RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({'|'.join(schema['locales'].keys())})(?:&|$) @@ -65,21 +65,21 @@ for country_code in htaccess_mapings.keys(): htaccess_mapings[country_code].sort(key=locale_sort_key) # Each rule is only applid is gzip encoding is accepted htaccess_rules += f'''RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({country_code}(-.*)?)(?:&|$) -RewriteRule ^schema(/.*)?$ /zotero-schema/locales/{htaccess_mapings[country_code][0]}.json.gz [QSD] +RewriteRule ^schema(/.*)?$ /zotero-schema/locales/{htaccess_mapings[country_code][0]}.json.gz [QSD,L] ''' # Catch all for default schema with all locales -htaccess_rules += '''RewriteRule ^schema$ /zotero-schema/schema.json.gz [QSD]''' +htaccess_rules += '''RewriteRule ^schema$ /zotero-schema/schema.json.gz [QSD,L]''' -#Rules to serve correct content type and prevent double gzip matching all locales -htaccess_rules += ''' -RewriteRule ^zotero-schema/schema\.json.gz$ - [T=application/json,E=no-gzip:1] -RewriteRule ^zotero-schema/locales/.*\.json.gz$ - [T=application/json,E=no-gzip:1]''' htaccess_rules += f''' # Serve correct encoding type Header append Content-Encoding gzip + # Set correct content type + Header set Content-Type application/json + # Prevent double-gzip + SetEnv no-gzip 1 # Force proxies to cache gzipped & non-gzipped schema file separately Header append Vary Accept-Encoding # CORS From 7aef704926c6b09a2c03449ce5fb58b3397817c7 Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Sat, 6 May 2023 16:00:44 -0400 Subject: [PATCH 10/11] No L in skip rule --- scripts/update-gz | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update-gz b/scripts/update-gz index 399fbd7..c2efca4 100755 --- a/scripts/update-gz +++ b/scripts/update-gz @@ -22,7 +22,7 @@ os.mkdir(locales_folder) # Begin by checking if gzip is supported. If not - return schema.json htaccess_rules = f'''RewriteCond %{{REQUEST_URI}} !^/schema -RewriteRule ".?" "-" [S=LINES_TO_SKIP,L] +RewriteRule ".?" "-" [S=LINES_TO_SKIP] RewriteCond %{{HTTP:Accept-Encoding}} !gzip RewriteRule ^schema(/.*)?$ /zotero-schema/schema.json [QSD,L] RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({'|'.join(schema['locales'].keys())})(?:&|$) From 393ffe5ea51b22399646d44c04322a5a4eda49a1 Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Mon, 8 May 2023 08:23:49 -0400 Subject: [PATCH 11/11] typo fix and last L --- scripts/update-gz | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/update-gz b/scripts/update-gz index c2efca4..6b3417b 100755 --- a/scripts/update-gz +++ b/scripts/update-gz @@ -26,7 +26,7 @@ RewriteRule ".?" "-" [S=LINES_TO_SKIP] RewriteCond %{{HTTP:Accept-Encoding}} !gzip RewriteRule ^schema(/.*)?$ /zotero-schema/schema.json [QSD,L] RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({'|'.join(schema['locales'].keys())})(?:&|$) -RewriteRule ^schema(/.*)?$ /zotero-schema/locales/%1.json.gz [QSD] +RewriteRule ^schema(/.*)?$ /zotero-schema/locales/%1.json.gz [QSD,L] ''' #Dict to collect country codes with locales to handle multiple locales per country code htaccess_mapings = {} @@ -63,7 +63,7 @@ def locale_sort_key(a): # For every country code, sort locale candidates and add rule to htacecss for country_code in htaccess_mapings.keys(): htaccess_mapings[country_code].sort(key=locale_sort_key) - # Each rule is only applid is gzip encoding is accepted + # Each rule is only applied if gzip encoding is accepted htaccess_rules += f'''RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({country_code}(-.*)?)(?:&|$) RewriteRule ^schema(/.*)?$ /zotero-schema/locales/{htaccess_mapings[country_code][0]}.json.gz [QSD,L] '''