设置自定义HTTP响应头中的Litespeed用PHP [英] Setting custom HTTP response headers in LiteSpeed with PHP

查看:303
本文介绍了设置自定义HTTP响应头中的Litespeed用PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置自定义HTTP 1.0状态code,以通过AJAX(使用jQuery)返回更具描述性的错误消息。

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

在PHP我有这样的:

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

这可以作为预期使用Apache 2.2.15我的开发环境,但它不能在运行的Litespeed 5.5生产Web服务器的工作。代替的Litespeed返回 200 OK

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.

使用这个:

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

阿帕奇返回 404 与上面的文字。的Litespeed替换默认的未找到自定义文本。

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

不知道如何在重写的Litespeed此功能,使其工作方式与Apache的一样吗?据我所知,他们应该是可比的Web服务器。

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

推荐答案

首先,为什么HTTP 1.0和1.1不?

First, why HTTP 1.0 and not 1.1?

二,你要做到这一点没有在HTTP规范中定义的东西。可能的Litespeed检查其头部被要求发送和替换它不与一些默认值认值。

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.

您不应该试图迫使HTTP在非标准的方式,只要你做的行为,它就不再是HTTP。规格在那里,以确保软件在不同的时间实现由不同的人可以互操作,以及应如何行事,如果你不遵循规范是完全不确定的。

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的一个头不通过知道是完全可以接受的行为,所以拒绝让它通过的Litespeed的行为。制作恶魔飞出你的鼻子也将是服务器在这种情况下,做一个有效的事情。而在客户端的意思与HTTP响应code不承认呢?

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!');

这篇关于设置自定义HTTP响应头中的Litespeed用PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆