-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5e71ec
commit 33dbb23
Showing
6 changed files
with
26 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ | |
* | ||
* Response body compression callback function for Ulfius Framework | ||
* | ||
* Copyright 2020-2022 Nicolas Mora <[email protected]> | ||
* Copyright 2020-2023 Nicolas Mora <[email protected]> | ||
* | ||
* Version 20221024 | ||
* Version 20231201 | ||
* | ||
* Compress the response body using `deflate` or `gzip` depending on the request header `Accept-Encoding` and the callback configuration. | ||
* The rest of the response, status, headers, cookies won't change. | ||
|
@@ -68,10 +68,10 @@ int callback_http_compression (const struct _u_request * request, struct _u_resp | |
char ** accept_list = NULL; | ||
int ret = U_CALLBACK_IGNORE, compress_mode = U_COMPRESS_NONE, res; | ||
z_stream defstream; | ||
char * data_zip = NULL; | ||
unsigned char * data_zip = NULL; | ||
size_t data_zip_len = 0; | ||
|
||
if (response->binary_body_length && u_map_has_key_case(request->map_header, U_ACCEPT_HEADER)) { | ||
if (response->binary_body_length && u_map_count_keys_case(request->map_header, U_ACCEPT_HEADER) == 1) { | ||
if (split_string(u_map_get_case(request->map_header, U_ACCEPT_HEADER), ",", &accept_list)) { | ||
if ((config == NULL || config->allow_gzip) && string_array_has_trimmed_value((const char **)accept_list, U_ACCEPT_GZIP)) { | ||
compress_mode = U_COMPRESS_GZIP; | ||
|
@@ -125,7 +125,7 @@ int callback_http_compression (const struct _u_request * request, struct _u_resp | |
} while (U_CALLBACK_IGNORE == ret && defstream.avail_out == 0); | ||
|
||
if (ret == U_CALLBACK_IGNORE) { | ||
ulfius_set_binary_body_response(response, (unsigned int)response->status, (const char *)data_zip, defstream.total_out); | ||
ulfius_set_binary_body_response(response, (unsigned int)response->status, (const unsigned char *)data_zip, defstream.total_out); | ||
u_map_put(response->map_header, U_CONTENT_HEADER, compress_mode==U_COMPRESS_GZIP?U_ACCEPT_GZIP:U_ACCEPT_DEFLATE); | ||
} | ||
deflateEnd(&defstream); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ | |
* | ||
* Response body compression callback function for Ulfius Framework | ||
* | ||
* Copyright 2020-2022 Nicolas Mora <[email protected]> | ||
* Copyright 2020-2023 Nicolas Mora <[email protected]> | ||
* | ||
* Version 20221024 | ||
* Version 20231201 | ||
* | ||
* Compress the response body using `deflate` or `gzip` depending on the request header `Accept-Encoding` and the callback configuration. | ||
* The rest of the response, status, headers, cookies won't change. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ | |
* | ||
* Iddawc OIDC Access Token token check | ||
* | ||
* Copyright 2021-2022 Nicolas Mora <[email protected]> | ||
* Copyright 2020-2023 Nicolas Mora <[email protected]> | ||
* | ||
* Version 20221024 | ||
* Version 20231201 | ||
* | ||
* The MIT License (MIT) | ||
* | ||
|
@@ -52,7 +52,7 @@ static const char * get_ip_source(const struct _u_request * request) { | |
} | ||
|
||
return ip_source; | ||
}; | ||
} | ||
|
||
static const char * get_auth_header_token(const char * auth_header, int * is_header_dpop) { | ||
if (0 == o_strncmp(HEADER_PREFIX_BEARER, auth_header, HEADER_PREFIX_BEARER_LEN)) { | ||
|
@@ -119,11 +119,12 @@ int callback_check_jwt_profile_access_token (const struct _u_request * request, | |
int res = U_CALLBACK_UNAUTHORIZED, res_validity, is_header_dpop = 0; | ||
const char * token_value = NULL, * dpop = u_map_get_case(request->map_header, HEADER_DPOP); | ||
char * response_value = NULL, * htu; | ||
int count_dpop = u_map_count_keys_case(request->map_header, HEADER_DPOP); | ||
|
||
if (config != NULL) { | ||
switch (config->method) { | ||
case I_METHOD_HEADER: | ||
if (u_map_get_case(request->map_header, HEADER_AUTHORIZATION) != NULL) { | ||
if (u_map_count_keys_case(request->map_header, HEADER_AUTHORIZATION) == 1) { | ||
token_value = get_auth_header_token(u_map_get_case(request->map_header, HEADER_AUTHORIZATION), &is_header_dpop); | ||
} | ||
break; | ||
|
@@ -150,9 +151,9 @@ int callback_check_jwt_profile_access_token (const struct _u_request * request, | |
u_map_put(response->map_header, HEADER_RESPONSE, response_value); | ||
o_free(response_value); | ||
} else { | ||
if (is_header_dpop && json_object_get(json_object_get(j_access_token, "cnf"), "jkt") != NULL && dpop != NULL) { | ||
if (is_header_dpop && json_object_get(json_object_get(j_access_token, "cnf"), "jkt") != NULL && dpop != NULL && count_dpop == 1) { | ||
htu = msprintf("%s%s", config->resource_url_root, request->url_path+1); | ||
if (i_verify_dpop_proof(u_map_get(request->map_header, I_HEADER_DPOP), request->http_verb, htu, config->dpop_max_iat, json_string_value(json_object_get(json_object_get(j_access_token, "cnf"), "jkt")), token_value) == I_OK) { | ||
if (i_verify_dpop_proof(u_map_get_case(request->map_header, I_HEADER_DPOP), request->http_verb, htu, config->dpop_max_iat, json_string_value(json_object_get(json_object_get(j_access_token, "cnf"), "jkt")), token_value) == I_OK) { | ||
res = U_CALLBACK_CONTINUE; | ||
if (ulfius_set_response_shared_data(response, json_deep_copy(j_access_token), (void (*)(void *))&json_decref) != U_OK) { | ||
res = U_CALLBACK_ERROR; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ | |
* | ||
* Iddawc OIDC Access Token token check | ||
* | ||
* Copyright 2021-2022 Nicolas Mora <[email protected]> | ||
* Copyright 2020-2023 Nicolas Mora <[email protected]> | ||
* | ||
* Version 20221024 | ||
* Version 20231201 | ||
* | ||
* The MIT License (MIT) | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* | ||
* Copyright 2020-2022 Nicolas Mora <[email protected]> | ||
* | ||
* Version 20221024 | ||
* Version 20231201 | ||
* | ||
* The MIT License (MIT) | ||
* | ||
|
@@ -303,7 +303,8 @@ int callback_static_compressed_inmemory_website (const struct _u_request * reque | |
unsigned char * file_content, * file_content_orig = NULL; | ||
size_t length, read_length, offset, data_zip_len = 0; | ||
FILE * f; | ||
char * file_requested, * file_path, * url_dup_save, * data_zip = NULL, * real_path = NULL; | ||
char * file_requested, * file_path, * url_dup_save, * real_path = NULL; | ||
unsigned char * data_zip = NULL; | ||
const char * content_type; | ||
|
||
/* | ||
|
@@ -343,7 +344,7 @@ int callback_static_compressed_inmemory_website (const struct _u_request * reque | |
|
||
if (compress_mode != U_COMPRESS_NONE) { | ||
if (compress_mode == U_COMPRESS_GZIP && config->allow_cache_compressed && u_map_has_key(&config->gzip_files, file_requested)) { | ||
ulfius_set_binary_body_response(response, 200, u_map_get(&config->gzip_files, file_requested), (size_t)u_map_get_length(&config->gzip_files, file_requested)); | ||
ulfius_set_binary_body_response(response, 200, (const unsigned char *)u_map_get(&config->gzip_files, file_requested), (size_t)u_map_get_length(&config->gzip_files, file_requested)); | ||
u_map_put(response->map_header, U_CONTENT_HEADER, U_ACCEPT_GZIP); | ||
|
||
content_type = u_map_get_case(&config->mime_types, get_filename_ext(file_requested)); | ||
|
@@ -353,7 +354,7 @@ int callback_static_compressed_inmemory_website (const struct _u_request * reque | |
u_map_put(response->map_header, "Content-Type", content_type); | ||
u_map_copy_into(response->map_header, &config->map_header); | ||
} else if (compress_mode == U_COMPRESS_DEFL && config->allow_cache_compressed && u_map_has_key(&config->deflate_files, file_requested)) { | ||
ulfius_set_binary_body_response(response, 200, u_map_get(&config->deflate_files, file_requested), (size_t)u_map_get_length(&config->deflate_files, file_requested)); | ||
ulfius_set_binary_body_response(response, 200, (const unsigned char *)u_map_get(&config->deflate_files, file_requested), (size_t)u_map_get_length(&config->deflate_files, file_requested)); | ||
u_map_put(response->map_header, U_CONTENT_HEADER, U_ACCEPT_DEFLATE); | ||
|
||
content_type = u_map_get_case(&config->mime_types, get_filename_ext(file_requested)); | ||
|
@@ -437,15 +438,15 @@ int callback_static_compressed_inmemory_website (const struct _u_request * reque | |
if (ret == U_CALLBACK_CONTINUE) { | ||
if (compress_mode == U_COMPRESS_GZIP) { | ||
if (config->allow_cache_compressed) { | ||
u_map_put_binary(&config->gzip_files, file_requested, data_zip, 0, defstream.total_out); | ||
ulfius_set_binary_body_response(response, 200, u_map_get(&config->gzip_files, file_requested), (size_t)u_map_get_length(&config->gzip_files, file_requested)); | ||
u_map_put_binary(&config->gzip_files, file_requested, (const char *)data_zip, 0, defstream.total_out); | ||
ulfius_set_binary_body_response(response, 200, (const unsigned char *)u_map_get(&config->gzip_files, file_requested), (size_t)u_map_get_length(&config->gzip_files, file_requested)); | ||
} else { | ||
ulfius_set_binary_body_response(response, 200, data_zip, defstream.total_out); | ||
} | ||
} else { | ||
if (config->allow_cache_compressed) { | ||
u_map_put_binary(&config->deflate_files, file_requested, data_zip, 0, defstream.total_out); | ||
ulfius_set_binary_body_response(response, 200, u_map_get(&config->deflate_files, file_requested), (size_t)u_map_get_length(&config->deflate_files, file_requested)); | ||
u_map_put_binary(&config->deflate_files, file_requested, (const char *)data_zip, 0, defstream.total_out); | ||
ulfius_set_binary_body_response(response, 200, (const unsigned char *)u_map_get(&config->deflate_files, file_requested), (size_t)u_map_get_length(&config->deflate_files, file_requested)); | ||
} else { | ||
ulfius_set_binary_body_response(response, 200, data_zip, defstream.total_out); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* | ||
* Copyright 2020-2022 Nicolas Mora <[email protected]> | ||
* | ||
* Version 20221024 | ||
* Version 20231201 | ||
* | ||
* The MIT License (MIT) | ||
* | ||
|