English 中文(简体)
Setting custom HTTP response headers in LiteSpeed with PHP
原标题:

I m trying to set a custom HTTP 1.0 status code in order to return more descriptive error messages via AJAX (using jQuery).

In PHP I have something like:

header(  HTTP/1.0 909 Hello World  );
exit;

This works as expected on my development environment using Apache 2.2.15 but it does not work on the production webserver running LiteSpeed 5.5. LiteSpeed instead returns a 200 OK.

Using this:

header(  HTTP/1.0 404 Hello World  );
exit;

Apache returns the 404 with the text above. LiteSpeed replaces the custom text with the default Not Found .

Any idea how to override this feature in LiteSpeed to make it work the same way as Apache? I understand they are supposed to be comparable webservers.

Any ideas, please do let me know.

-P.

最佳回答

First, why HTTP 1.0 and not 1.1?

Second, you re trying to do things that aren t defined in the HTTP spec. LiteSpeed probably checks the headers its being asked to send and replaces values it doesn t recognise with some default value.

You shouldn t be trying to force HTTP to behave in a non-standard way, as soon as you do, it ceases to be HTTP. The specifications are there to make sure that software implemented at different times by different people can interoperate, and how it should behave if you don t follow the spec is completely undefined.

Apache letting a header it doesn t know through is perfectly acceptable behaviour, and so is LiteSpeed s behaviour of refusing to let it through. Making demons fly out of your nose would also be a valid thing for the server to do in this case. And what is the client meant to do with an HTTP response code it doesn t recognise?

If you need to send additional information in the header, why not add a new header? The following should do.

header ( X-My-App-Header: Hello World! );
问题回答

暂无回答




相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签