Skip to content
Myr

Drop Content-Length headers on GET redirects

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Christie · committed by Tom Christie · parent b8c5e7a · Browse files · 1 file+12 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+12 added−5 removed

  • other:+12 added−5 removed

1 file+12 added−5 removed

modified:httpx/middleware.py+12 added-5 removed
86 unmodified lines
87 self, request: AsyncRequest, response: AsyncResponse88 ) -> AsyncRequest:89 method = self.redirect_method(request, response)90 url = self.redirect_url(request, response)91 headers = self.redirect_headers(request, url) # TODO: merge headers?91 headers = self.redirect_headers(request, url, method) # TODO: merge headers?92 content = self.redirect_content(request, method)93 cookies = Cookies(self.cookies)94 cookies.update(request.cookies)95 return AsyncRequest(
41 unmodified lines
137 url = url.copy_with(fragment=request.url.fragment)138139 return url140141 def redirect_headers(self, request: AsyncRequest, url: URL) -> Headers:141 def redirect_headers(self, request: AsyncRequest, url: URL, method: str) -> Headers:142 """143 Strip Authorization headers when responses are redirected away from144 the origin.143 Return the headers that should be used for the redirect request.144 """145 headers = Headers(request.headers)146147 if url.origin != request.url.origin:148 # Strip Authorization headers when responses are redirected away from149 # the origin.150 del headers["Authorization"]149 del headers["host"]151 del headers["Host"]152153 if method != request.method and method == "GET":154 # Strip Content-Length headers when we've switch to a 'GET' request.155 del headers["Content-Length"]156157 return headers158159 def redirect_content(self, request: AsyncRequest, method: str) -> bytes:160 """
7 unmodified lines