代码之家  ›  专栏  ›  技术社区  ›  user1119648

AWS/EC2状态文本从响应中删除

  •  1
  • user1119648  · 技术社区  · 7 年前

    我的应用程序部署在EC2实例上的一组docker容器上。在本地开发环境中,我使用相同的docker容器集。我的应用程序发回statusText标题以显示有意义的错误消息。在我的本地环境中,所有这些statusText标头都会返回一个很好的响应,但是当AWS部署了完全相同的代码时,statusText标头始终为空,浏览器似乎会将其解释为“OK”。我设置的状态码返回正确。

    tl;dr:有人知道AWS或EC2上会从响应标题中删除statusText的任何行为吗?我在文档中找不到任何东西。

    这不会返回状态文本:

    server {
        listen       443 http2 ssl;
        server_name  api.example.com;
        root         /var/www/api/public;
    
        error_log    /var/log/nginx/api.error.log;
    
        client_max_body_size 16M;
    
        include ssl.conf;
    
        location / {
            if ($request_method = OPTIONS ) {
                add_header Access-Control-Allow-Origin  '$cors_host';
                add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE,  OPTIONS";
                add_header Access-Control-Allow-Headers "$http_access_control_request_headers";
                add_header Content-Length 0;
                add_header Content-Type 'text/plain; charset=utf-8';
                return 204;
            }
            add_header Access-Control-Allow-Origin '$cors_host';
            try_files $uri $uri/ /index.php?_url=$uri&$args;
        }
    
        include fastcgi_exec.conf;
    }
    

    这会:

    server {
        listen       80;
        server_name  api.example.dev;
        root         /var/www/api/public;
    
        error_log    /var/log/nginx/api.error.log;
    
        client_max_body_size 16M;
    
        location / {
            if ($request_method = OPTIONS ) {
                add_header Access-Control-Allow-Origin $http_origin;
                add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
                add_header Access-Control-Allow-Headers $http_access_control_request_headers;
                add_header Content-Length 0;
                add_header Content-Type text/plain;
                return 200;
            }
            try_files $uri $uri/ /index.php?_url=$uri&$args;
        }
    
        include fastcgi_exec.conf;
    
    }
    
    1 回复  |  直到 7 年前
        1
  •  3
  •   Michael - sqlbot    7 年前

    HTTP/2没有保留HTTP/1中的“原因短语”(状态消息)。x。

    HTTP/2没有定义一种方式来携带包含在HTTP/1.1状态行中的版本或原因短语。

    https://http2.github.io/http2-spec/#HttpSequence