0

I have this configuration in my nginx :

location ~* ^/test(.*) {
    add_header "Access-Control-Allow-Origin" $http_origin;
    add_header "Access-Control-Allow-Credentials" "true";
    # PLEASE NOT THIS ONE, IT IS SEPARATED BY NEWLINE
    add_header "Access-Control-Allow-Headers" "Access-Control-Allow-Origin,Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Re
 quested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,sid_internal,access_token,Referer";
    add_header "Access-Control-Allow-Methods" "GET,POST,DELETE,OPTIONS,PATCH";
    # Preflighted requests
    if ($request_method = OPTIONS ) {
        add_header "Access-Control-Allow-Origin" $http_origin;
        add_header "Access-Control-Allow-Credentials" "true";
        add_header "Access-Control-Allow-Methods" "GET,POST,DELETE,OPTIONS,HEAD,PATCH";
        # PLEASE NOT THIS ONE, IT IS SEPARATED BY NEWLINE
        add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept, sid_internal, access_token, R
 eferer";
        return 204;
    }

Suppose the server name is example.com

When I hit https://example.com/test :

  • With Chrome and Opera Browser, I got HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR
  • With Firefox, it works perfectly fine
  • When I do curl from my linux terminal, I got HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR

But, I do some fixing by removing the newline separated config in nginx, so it become like this :

location ~* ^/test(.*) {
    add_header "Access-Control-Allow-Origin" $http_origin;
    add_header "Access-Control-Allow-Credentials" "true";
    # PLEASE NOTE THIS ONE, NEWLINE REMOVED
    add_header "Access-Control-Allow-Headers" "Access-Control-Allow-Origin,Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,sid_internal,access_token,Referer";
    add_header "Access-Control-Allow-Methods" "GET,POST,DELETE,OPTIONS,PATCH";
    # Preflighted requests
    if ($request_method = OPTIONS ) {
        add_header "Access-Control-Allow-Origin" $http_origin;
        add_header "Access-Control-Allow-Credentials" "true";
        add_header "Access-Control-Allow-Methods" "GET,POST,DELETE,OPTIONS,HEAD,PATCH";
        # PLEASE NOTE THIS ONE, NEWLINE REMOVED
        add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept, sid_internal, access_token, Referer";
        return 204;
    }

After I change that nginx config, all is working (in chrome, in opera, and in my linux terminal)

Well, my problem is actually solved.

But just wondering, anyone knows why the first nginx config (the one with newline separator) caused a PROTOCOL_ERROR ?

xemjas
  • 115
  • 4
  • 16

1 Answers1

1

It is probably not possible to have a new line character in the header value in HTTP/2. I saw the same error PROTOCOL_ERROR after I wrongly put both header name with it's value as the first argument: add_header "Something: value";

HTTP/2 seem to be more strict regarding the headers.

k3a
  • 1,296
  • 1
  • 15
  • 32