static lwan_http_status_t module_redirect_to(lwan_request_t *request, const char *url) { lwan_key_value_t *headers = coro_malloc(request->conn->coro, sizeof(*headers) * 2); if (UNLIKELY(!headers)) return HTTP_INTERNAL_ERROR; headers[0].key = "Location"; headers[0].value = coro_strdup(request->conn->coro, url); if (UNLIKELY(!headers[0].value)) return HTTP_INTERNAL_ERROR; headers[1].key = NULL; headers[1].value = NULL; request->response.headers = headers; return HTTP_MOVED_PERMANENTLY; }
static enum lwan_http_status redirect_handle_request(struct lwan_request *request, struct lwan_response *response, void *instance) { if (UNLIKELY(!instance)) return HTTP_INTERNAL_ERROR; struct lwan_key_value *headers = coro_malloc(request->conn->coro, sizeof(*headers) * 2); if (UNLIKELY(!headers)) return HTTP_INTERNAL_ERROR; headers[0].key = "Location"; headers[0].value = instance; headers[1].key = NULL; headers[1].value = NULL; response->headers = headers; return HTTP_MOVED_PERMANENTLY; }