Skip to content

Commit

Permalink
Add Location header for newly created groups/clients/domains/lists
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Jan 6, 2024
1 parent 977acf4 commit 8806f64
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/api/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,20 @@ static int api_list_write(struct ftl_conn *api,
if(api->method == HTTP_PUT)
response_code = 200; // 200 - OK

// Add "Location" header to response
if(snprintf(pi_hole_extra_headers, sizeof(pi_hole_extra_headers), "Location: %s/%s", api->action_path, row.item) >= (int)sizeof(pi_hole_extra_headers))
{
// This may happen for *extremely* long URLs but is not issue in
// itself. Merely add a warning to the log file
log_warn("Could not add Location header to response: URL too long");

// Truncate location by replacing the last characters with "...\0"
pi_hole_extra_headers[sizeof(pi_hole_extra_headers)-4] = '.';
pi_hole_extra_headers[sizeof(pi_hole_extra_headers)-3] = '.';
pi_hole_extra_headers[sizeof(pi_hole_extra_headers)-2] = '.';
pi_hole_extra_headers[sizeof(pi_hole_extra_headers)-1] = '\0';
}

// Send GET style reply
const int ret = api_list_read(api, response_code, listtype, row.item, processed);

Expand Down

0 comments on commit 8806f64

Please sign in to comment.