Skip to content

Conversation

Vizonex
Copy link
Contributor

@Vizonex Vizonex commented Sep 17, 2025

What do these changes do?

Many users have begged for http2 protocols and website use http2 to talk to legitimate users. With the rise of this new technologies hosting with http/2 as well as webscraping or using http2 with apis is now in demand. This is a concept for http2 support using hpack & hyperframe.

With httpx supporting http2 protocols already were behind and could use a little bit of the newer protocols ourselves.

I am requesting some assistance with figuring things out including injection of http2 for different kinds of requests or clients that are requesting http/2. (Hence why this is still a draft)

Are there changes in behavior for the user?

HTTP/2 will be added in and allow users to communicate with servers that have http/2 support.

Is it a substantial burden for the maintainers to support this?

The only burden I see is when we start to introduce more things and I have talked heavily on matrix about finding and hunting C libraries or making our own and yes have one already made one for parsing frames :) but we first need a pure python concept before we can use this llh2 library I came up with and more so the pure python stuff is what we will focus on tackling first.

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_or_pr_num>.<type>.rst (e.g. 588.bugfix.rst)

    • if you don't have an issue number, change it to the pull request
      number after creating the PR

      • .bugfix: A bug fix for something the maintainers deemed an
        improper undesired behavior that got corrected to match
        pre-agreed expectations.
      • .feature: A new behavior, public APIs. That sort of stuff.
      • .deprecation: A declaration of future API removals and breaking
        changes in behavior.
      • .breaking: When something public is removed in a breaking way.
        Could be deprecated in an earlier release.
      • .doc: Notable updates to the documentation structure or build
        process.
      • .packaging: Notes for downstreams about unobvious side effects
        and tooling. Changes in the test invocation considerations and
        runtime assumptions.
      • .contrib: Stuff that affects the contributor experience. e.g.
        Running tests, building the docs, setting up the development
        environment.
      • .misc: Changes that are hard to assign to any of the above
        categories.
    • Make sure to use full sentences with correct case and punctuation,
      for example:

      Fixed issue with non-ascii contents in doctest text files
      -- by :user:`contributor-gh-handle`.

      Use the past tense or the present tense a non-imperative mood,
      referring to what's changed compared to the last released version
      of this project.

@@ -0,0 +1,192 @@
import base64 # TODO: Pybase64 or libbase64 in Cython would be a good idea here...

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'base64' is not used.
from hpack.hpack import Decoder
from http_writer import HttpVersion, HttpVersion20
from hyperframe.frame import ContinuationFrame, Frame, GoAwayFrame, HeadersFrame
from multidict import CIMultiDict, CIMultiDictProxy, istr

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'CIMultiDictProxy' is not used.
Import of 'istr' is not used.
from multidict import CIMultiDict, CIMultiDictProxy, istr
from yarl import URL

from . import hdrs

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'hdrs' is not used.
Comment on lines +26 to +32
BrotliDecompressor,
ZLibDecompressor,
ZSTDDecompressor,
)
from .http_parser import RawRequestMessage, RawResponseMessage, _MsgT
from .streams import EMPTY_PAYLOAD, StreamReader
from .typedefs import RawHeaders

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'HAS_BROTLI' is not used.
Import of 'HAS_ZSTD' is not used.
Import of 'BrotliDecompressor' is not used.
Import of 'ZLibDecompressor' is not used.
Import of 'ZSTDDecompressor' is not used.
ZSTDDecompressor,
)
from .http_parser import RawRequestMessage, RawResponseMessage, _MsgT
from .streams import EMPTY_PAYLOAD, StreamReader

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'EMPTY_PAYLOAD' is not used.
Import of 'StreamReader' is not used.
)
from .http_parser import RawRequestMessage, RawResponseMessage, _MsgT
from .streams import EMPTY_PAYLOAD, StreamReader
from .typedefs import RawHeaders

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'RawHeaders' is not used.

# Reflects h2/connection from a lower-level prespective so
# socket writing can be a bit more optimized.
from hpack.hpack import Decoder, Encoder

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'Decoder' is not used.
from .base_protocol import BaseProtocol
from .client_exceptions import ClientConnectionResetError
from .compression_utils import ZLibCompressor
from .helpers import NO_EXTENSIONS

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'NO_EXTENSIONS' is not used.
Copy link

codspeed-hq bot commented Sep 17, 2025

CodSpeed Performance Report

Merging #11522 will not alter performance

Comparing Vizonex:http2 (f89c153) with master (230e1ee)

Summary

✅ 59 untouched

@Dreamsorcerer
Copy link
Member

Dreamsorcerer commented Sep 19, 2025

We probably need some tests (and it actually being linked together to the rest of the project) showing the implementation working before we review this.

@Vizonex
Copy link
Contributor Author

Vizonex commented Sep 19, 2025

We probably need some tests (and it actually being linked together to the rest of the project) showing the implementation working before we review this.

Sure thing ^^ This is a draft after all and I will need help and suggestions in the matrix if I need it I want to create a dynamic setup when swapping from http/1.1 to http/2 before I start the PR. I thought about writing a abstract class object for the transitioning with all the inner stuff like sockets and things but let me see about making that and finding a dummy server that has http2 before I begin.

@Dreamsorcerer
Copy link
Member

Also, isn't h2 meant to handle most of this? I'm wondering if you've not just started recreating h2..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants