Repository navigation
XHTTP server: Accept OPTIONS as uplinkHTTPMethod - #7290
Conversation
|
GET够了吧 OPTIONS 更奇怪了 |
|
Thanks for looking at this. Not trying to reopen, just a few facts in case they change the picture. Why a non-POST method matters. Yandex Cloud CDN allows only Why GET is not enough.
What the change does. Today |
|
可以加 |
uplinkHTTPMethod
- The HTTP/2 client transport dials one connection at a time (MaxConnsPerHost 1). Requests that start together used to open a connection each: 16 requests on a fresh transport made 13 connections, and 16 while a TLS handshake hung made 16 (XTLS/Xray-core#6797). That burst of handshakes is a pattern censors look for and it went past reuse-settings max-connections. They now share one dial; more connections open only when the server's stream limit is reached. - packet-up requests set GetBody, so HTTP/2 can send a packet again on a new connection after a GOAWAY instead of failing it (XTLS/Xray-core#6632). - The server takes an OPTIONS request without Access-Control-Request-Method as an upload, as Xray does since XTLS/Xray-core#7290; before, every OPTIONS was answered as a CORS preflight and uplink-http-method OPTIONS did not work.
- The HTTP/2 client transport dials one connection at a time (MaxConnsPerHost 1). Requests that start together used to open a connection each: 16 requests on a fresh transport made 13 connections, and 16 while a TLS handshake hung made 16 (XTLS/Xray-core#6797). That burst of handshakes is a pattern censors look for and it went past reuse-settings max-connections. They now share one dial; more connections open only when the server's stream limit is reached. - packet-up requests set GetBody, so HTTP/2 can send a packet again on a new connection after a GOAWAY instead of failing it (XTLS/Xray-core#6632). - The server takes an OPTIONS request without Access-Control-Request-Method as an upload, as Xray does since XTLS/Xray-core#7290; before, every OPTIONS was answered as a CORS preflight and uplink-http-method OPTIONS did not work.
uplinkHTTPMethodaccepts any method except GET outside packet-up (infra/conf/transport_method.go), and the client sends the configured method as is. So"uplinkHTTPMethod": "OPTIONS"passes config validation, but the server never processes such a request.Cause.
requestHandler.ServeHTTPanswers everyOPTIONSrequest with200right after writing the padding/CORS headers, treating it as a CORS preflight. An uplink request sent withOPTIONSis dropped there, so its body is never read and the session stalls.Change. Treat
OPTIONSas a preflight only when it carriesAccess-Control-Request-Method, which every browser preflight has. Any otherOPTIONSrequest goes through the normal uplink handling (the existing code already treats every non-GET method as an uplink). Behaviour for POST/PUT/GET and for real preflights is unchanged. No config or protocol change; clients need no update.Tests (
transport/internet/splithttp):Test_UplinkHTTPMethodOptions: echo over packet-up, stream-up, stream-one and auto, plain and TLS, with POST, PUT and OPTIONS. Without the change OPTIONS times out or gets EOF in every mode; with it all pass (also 20x with-race).Test_CORSPreflightStillAnswered: a preflight withAccess-Control-Request-Methodstill gets200andAccess-Control-Allow-Methods.Test_ServerMaxHeaderBytes: oversized headers are rejected with 431 (this setting had no test).Also checked end to end with real binaries: VLESS+XHTTP packet-up,
uplinkHTTPMethod: OPTIONS, unmodified client against the patched server returns data; the same config against an unpatched server does not.go run ./infra/vformat/main.go -mode check -pwd ./,go run ./infra/vprotogen/main.go -mode check -pwd ./andgo test ./...pass locally (macOS arm64; the TLS cases of the new test were run with the package's arm64 skip lifted).