2014-11-19 3 views
1

Я пытаюсь создать простой асинхронный веб-сервис с Apache и mod_perl. Но каждый раз, когда я пытаюсь вернуть HTTP-статус 202 (Accepted), я получаю сообщение об ошибке.Ошибка mod_perl 202 Apache2 :: Const :: HTTP_ACCEPTED

Ниже представлен простой пример (не асинхронное):

package MyHandler; 

use Apache2::Const '-compile' => qw 'OK HTTP_ACCEPTED HTTP_OK'; 
use Apache2::RequestRec; 
use CGI; 

sub handler { 
     my $r = shift; 
     print "Hallo"; 
     $r->content_type('text/plain'); 
     $r->status(Apache2::Const::HTTP_ACCEPTED); 
     return Apache2::Const::HTTP_ACCEPTED; 
} 

1; 

Я получаю ошибку

вызовом обработчика в браузере на локальном хосте, я получаю выход, но и об ошибке:

Hallo 
Accepted 

The server encountered an internal error or misconfiguration and was unable to complete your request. 
Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error. 
More information about this error may be available in the server error log. 

Я также получаю сообщение об ошибке Apache2::Const::HTTP_OK, единственный, который работает без ошибок, - Apache2::Const::OK.

В моем журнале ошибок apache не упоминается об этой ошибке.

+0

Что вы апач журнал ошибок сказать по этому вопросу? –

+0

aah забыл упомянуть: журнал ошибок ничего не сказал об этом! Я отредактирую сообщение. – user1981275

+0

Мне трудно поверить. –

ответ

-1

Не пытайтесь напечатать что-либо ДО того, как вы установите заголовок содержимого.

+0

Еще ошибка. Я не уверен, действительно ли на самом деле печатает его тип содержимого с content_type. – user1981275

+0

Документация mod_perl (http://perl.apache.org/docs/1.0/guide/porting.html) говорит мне, что мне действительно не нужно ее устанавливать, так как она позаботилась об аппахе в соответствии с требованиями. Однако '$ r-> content_type ('text/plain');': все еще ошибка. – user1981275

2

С mod_perl2 вы не возвращает код статуса HTTP (поэтому необходимо использовать $r->status() так установить код статуса HTTP.

Вместо этого возвращать значение в зависимости от того, что вы хотите, чтобы сервер делать. наиболее распространенным будет Apache2::Const::OK. Это говорит серверу обработчик закончил успешно. Эта константа, если я правильно помню, имеет целочисленное значение 0, не 200.

Возвращаясь к HTTP-код состояния от обработчика mod_perl будет интерпретируется как ошибка.

https://perl.apache.org/docs/2.0/user/handlers/intro.html#Handler_Return_Values

Different handler groups are supposed to return different values.

Make sure that you always explicitly return a wanted value and don't rely on the result of last expression to be used as the return value -- things will change in the future and you won't know why things aren't working anymore.

The only value that can be returned by all handlers is Apache2::Const::OK, which tells Apache that the handler has successfully finished its execution.

Apache2::Const::DECLINED is another return value that indicates success, but it's only relevant for phases of type RUN_FIRST.

HTTP handlers may also return Apache2::Const::DONE which tells Apache to stop the normal HTTP request cycle and fast forward to the PerlLogHandler, followed by PerlCleanupHandler. HTTP handlers may return any HTTP status, which similarly to Apache2::Const::DONE will cause an abort of the request cycle, by also will be interpreted as an error. Therefore you don't want to return Apache2::Const::HTTP_OK from your HTTP response handler, but Apache2::Const::OK and Apache will send the 200 OK status by itself.

 Смежные вопросы

  • Нет связанных вопросов^_^