From e960c4e7bac5a6872055638f5291b79c2aafa51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 21 Nov 2022 15:46:19 +0100 Subject: Support positive HTTP/1.0 responses to CONNECT requests --- src/gun_http.erl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gun_http.erl b/src/gun_http.erl index 38806d0..18d019e 100644 --- a/src/gun_http.erl +++ b/src/gun_http.erl @@ -301,16 +301,20 @@ handle_head(Data, State=#http_state{opts=Opts, Authority, Path, Status, Headers, CookieStore0, Opts), case StreamRef of {connect, _, _} when Status >= 200, Status < 300 -> - handle_connect(Rest, State, CookieStore, EvHandler, EvHandlerState, Version, Status, Headers); + handle_connect(Rest, State, CookieStore, EvHandler, EvHandlerState, Status, Headers); _ when Status >= 100, Status =< 199 -> handle_inform(Rest, State, CookieStore, EvHandler, EvHandlerState, Version, Status, Headers); _ -> handle_response(Rest, State, CookieStore, EvHandler, EvHandlerState, Version, Status, Headers) end. +%% We handle HTTP/1.0 responses to CONNECT requests the same as HTTP/1.1. +%% This is because many proxies have historically used HTTP/1.0 for their +%% response. The HTTP/1.1 specification does not disallow it: servers that +%% respond positively to a CONNECT request are supposed to implement it. handle_connect(Rest, State=#http_state{ streams=[Stream=#stream{ref={_, StreamRef, Destination}, reply_to=ReplyTo}|Tail]}, - CookieStore, EvHandler, EvHandlerState0, 'HTTP/1.1', Status, Headers) -> + CookieStore, EvHandler, EvHandlerState0, Status, Headers) -> RealStreamRef = stream_ref(State, StreamRef), %% @todo If the stream is cancelled we probably shouldn't finish the CONNECT setup. _ = case Stream of -- cgit v1.2.3