From: Nick Porter Date: Wed, 30 Jul 2025 13:03:28 +0000 (+0100) Subject: When %rest() get a failure HTTP status code capture the body in REST-HTTP-Body X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1a44eb6b2deb2af83cdb3be326dee7be89b8e2c;p=thirdparty%2Ffreeradius-server.git When %rest() get a failure HTTP status code capture the body in REST-HTTP-Body Recent correction to rcode handling have resulted in xlats which return XLAT_ACTION_FAIL having their output disgarded, so the previous behaviour of %rest() was lost. This approach gives more consistent behaviour with other xlats, but still allows access to any errors reported by the server in the reply body. --- diff --git a/src/modules/rlm_rest/rlm_rest.c b/src/modules/rlm_rest/rlm_rest.c index cddd8da574..2fc59b55bc 100644 --- a/src/modules/rlm_rest/rlm_rest.c +++ b/src/modules/rlm_rest/rlm_rest.c @@ -424,9 +424,19 @@ static xlat_action_t rest_xlat_resume(TALLOC_CTX *ctx, fr_dcursor_t *out, case 403: case 401: { + fr_pair_t *vp; xa = XLAT_ACTION_FAIL; error: rest_response_error(request, handle); + + /* + * When the HTTP status code is a failure, put the + * response body in REST-HTTP-Body. + */ + len = rest_get_handle_data(&body, handle); + if (len == 0) goto finish; + MEM(pair_update_request(&vp, attr_rest_http_body) >= 0); + fr_pair_value_bstrndup(vp, body, len, true); goto finish; } case 204: @@ -447,9 +457,8 @@ error: } } -finish: /* - * Always output the xlat data. + * Output the xlat data if the HTTP status code is one of the "success" ones. * * The user can check REST-HTTP-Status-Code to figure out what happened. * @@ -464,6 +473,7 @@ finish: fr_value_box_bstrndup(vb, vb, NULL, body, len, true); fr_dcursor_insert(out, vb); } +finish: rest_slab_release(handle);