Skip to content

Commit

Permalink
Deprecate t.w.h.HTTPClient
Browse files Browse the repository at this point in the history
  • Loading branch information
twm committed May 6, 2024
1 parent 625a86c commit 81c3f1b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/twisted/web/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
it, as in the HTTP 1.1 chunked I{Transfer-Encoding} (RFC 7230 section 4.1).
This limits how much data may be buffered when decoding the line.
"""

from __future__ import annotations

__all__ = [
Expand Down Expand Up @@ -131,7 +132,7 @@
from twisted.python import log
from twisted.python.compat import nativeString, networkString
from twisted.python.components import proxyForInterface
from twisted.python.deprecate import deprecated
from twisted.python.deprecate import deprecated, deprecatedModuleAttribute
from twisted.python.failure import Failure
from twisted.web._responses import (
ACCEPTED,
Expand Down Expand Up @@ -771,6 +772,14 @@ def rawDataReceived(self, data):
self.setLineMode(rest)


deprecatedModuleAttribute(
Version("Twisted", "NEXT", 0, 0),
"Use twisted.web.client.Agent instead.",
__name__,
HTTPClient.__name__,
)


# response codes that must have empty bodies
NO_BODY_CODES = (204, 304)

Expand Down
7 changes: 4 additions & 3 deletions src/twisted/web/iweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
L{IBodyProducer.length} to indicate that the length of the entity
body is not known in advance.
"""

from typing import TYPE_CHECKING, Callable, List, Optional

from zope.interface import Attribute, Interface
Expand Down Expand Up @@ -595,15 +596,15 @@ def deliverBody(protocol):
L{IPushProducer}. The protocol's C{connectionLost} method will be
called with:
- ResponseDone, which indicates that all bytes from the response
- L{ResponseDone}, which indicates that all bytes from the response
have been successfully delivered.
- PotentialDataLoss, which indicates that it cannot be determined
- L{PotentialDataLoss}, which indicates that it cannot be determined
if the entire response body has been delivered. This only occurs
when making requests to HTTP servers which do not set
I{Content-Length} or a I{Transfer-Encoding} in the response.
- ResponseFailed, which indicates that some bytes from the response
- L{ResponseFailed}, which indicates that some bytes from the response
were lost. The C{reasons} attribute of the exception may provide
more specific indications as to why.
"""
Expand Down
1 change: 1 addition & 0 deletions src/twisted/web/newsfragments/12158.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
twisted.web.http.HTTPClient is now deprecated in favor of twisted.web.client.Agent
18 changes: 17 additions & 1 deletion src/twisted/web/test/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Test HTTP support.
"""


import base64
import calendar
import random
Expand All @@ -20,6 +19,7 @@
from zope.interface.verify import verifyObject

import hamcrest
from incremental import Version

from twisted.internet import address
from twisted.internet.error import ConnectionDone, ConnectionLost
Expand Down Expand Up @@ -4407,6 +4407,22 @@ def test_writeHeadersSanitizesLinearWhitespace(self):
)


class HTTPClientDeprecationTests(unittest.SynchronousTestCase):
"""
Test that L{http.HTTPClient} is deprecated.
"""

def test_deprecated(self):
"""
Accessing L{http.HTTPClient} produces a deprecation warning.
"""
self.getDeprecatedModuleAttribute(
"twisted.web.http",
"HTTPClient",
Version("Twisted", "NEXT", 0, 0),
)


class HTTPClientSanitizationTests(unittest.SynchronousTestCase):
"""
Test that L{http.HTTPClient} sanitizes its output.
Expand Down

0 comments on commit 81c3f1b

Please sign in to comment.