Форум ApacheDev

Apache isn't the fastest or maximally customizable web server, its popularity comes from the fact that it provides a very good balance of these things bundled with maximum portability and reliability.

Вы не зашли.

#1 2007-09-20 00:13:44

unknow
Новичок
Зарегистрирован: 2007-03-01
Сообщений: 15
Рейтинг :   

Как грамотно завершить запрос

Есть функция обратного вызова устанавливаемая вызовом ap_hook_post_read_request(post_read_request, NULL,NULL, APR_HOOK_REALLY_FIRST);

В обработчике я бы хотел обработат ьзапрос, так что-бы он далее не пошел фильтрам и другим модулям.

т.е. я хотел бы сам генерировать ответ, мне кажется что очевиднее так:

ap_rputs("<html><head>\n<title>XXX</title>\n</head><body>hello</body></html>\n",r);
    r->status_line = "200 OK";
    return HTTP_OK;

но на деле браузер получает странный ответ:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>200 OK</title>
</head><body>
<h1>OK</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
@@ServerAdmin@@ and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
</body></html>


Облом происходит в функции
AP_DECLARE(void) ap_die(int type, request_rec *r)
{
    int error_index = ap_index_of_response(type);
    char *custom_response = ap_response_code_string(r, error_index);
    int recursive_error = 0;
    request_rec *r_1st_err = r;

    if (type == AP_FILTER_ERROR) {
        return;
    }

    if (type == DONE) {
        ap_finalize_request_protocol(r);
        return;
    }

    /*
     * The following takes care of Apache redirects to custom response URLs
     * Note that if we are already dealing with the response to some other
     * error condition, we just report on the original error, and give up on
     * any attempt to handle the other thing "intelligently"...
     */
    if (r->status != HTTP_OK) {
        recursive_error = type;

char *ap_response_code_string(request_rec *r, int error_index)
{
    core_dir_config *dirconf;
    core_request_config *reqconf;

    /* check for string registered via ap_custom_response() first */
    reqconf = (core_request_config *)ap_get_module_config(r->request_config,
                                                          &core_module);
    if (reqconf->response_code_strings != NULL &&
        reqconf->response_code_strings[error_index] != NULL) {
        return reqconf->response_code_strings[error_index];
    }


В общем считается что не удалось получить конфиг модуля, поэтому это ошибка и нужно сгенерировать такой ответ.

Отредактированно unknow (2007-09-20 00:14:02)

Неактивен

 

#2 2007-09-23 23:44:47

unknow
Новичок
Зарегистрирован: 2007-03-01
Сообщений: 15
Рейтинг :   

Re: Как грамотно завершить запрос

Отвечаю на свой вопрос:)
ap_hook_post_read_request в этом обработчике все же не получается выдать в ответе некоторые данные и установить 200 OK
все равно сервер генерирует ошибку в ответе клиенту. Код ошибки установить - да можно.

Выдать данные и установить код ошибки можно в обработчике ap_hook_handler, т.е. в момент генерации контента.

Неактивен

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson