Skip to content

HTTP Pipelining Example

Andrew Lambert edited this page Nov 5, 2023 · 13 revisions

libcURL can pipeline several HTTP requests over a single connection. This example downloads three files over HTTP. If the server supports pipelining then they will all use the same connection.

  Dim transfer1 As New libcURL.EasyHandle
  Dim transfer2 As New libcURL.EasyHandle
  Dim transfer3 As New libcURL.EasyHandle
  
  ' set up first transfer
  transfer1.URL = "http://www.example.com/page.html"
  Dim t1 As BinaryStream = BinaryStream.Create(SpecialFolder.Desktop.Child("page.html"), False)
  transfer1.DownloadStream = t1
  ' second
  transfer2.URL = "http://www.example.com/style.css"
  Dim t2 As BinaryStream = BinaryStream.Create(SpecialFolder.Desktop.Child("style.css"), False)
  transfer2.DownloadStream = t2
  ' third
  transfer3.URL = "http://www.example.com/scripts.js"
  Dim t3 As BinaryStream = BinaryStream.Create(SpecialFolder.Desktop.Child("scripts.js"), False)
  transfer3.DownloadStream = t3
  
  ' add the transfers to a MultiHandle
  Dim m As New libcURL.MultiHandle
  m.AddTransfer(transfer1)
  m.AddTransfer(transfer2)
  m.AddTransfer(transfer3)
  
  ' enable pipelining
  m.HTTPPipelining = True ' or HTTPMultiplexing if using HTTP2
  
  ' perform the transfers
  Do Until Not m.PerformOnce()
    App.YieldToNextThread
  Loop
  ' clean up
  t1.Close
  t2.Close
  t3.Close
Clone this wiki locally