snapshot of https://github.com/pion/webrtc.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
REUSE Compliance Check / lint (push) Failing after 0s
Browser E2E / Test (push) Failing after 3s
Test / test (1.24) (push) Failing after 0s
Test / test-i386 (1.25) (push) Failing after 0s
Test / test-i386 (1.24) (push) Failing after 0s
Test / test-windows (1.25) (push) Failing after 0s
Test / test-windows (1.24) (push) Failing after 0s
Test / test (1.25) (push) Failing after 0s
Examples Tests / Test (push) Failing after 3s
Test / test-macos (1.25) (push) Failing after 0s
Test / test-macos (1.24) (push) Failing after 0s
Go mod tidy / tidy (push) Failing after 0s
Test / test-wasm (push) Failing after 0s
CodeQL / analyze (push) Failing after 1s
Fuzz / fuzz (push) Failing after 0s

This commit is contained in:
upstream-mirror
2026-09-15 20:06:07 +05:00
commit 8acb1a3a29
394 changed files with 78746 additions and 0 deletions

124
examples/ice-proxy/proxy.go Normal file
View File

@@ -0,0 +1,124 @@
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
//go:build !js
package main
import (
"bufio"
"fmt"
"io"
"log"
"net"
"net/http"
"net/url"
"golang.org/x/net/proxy"
)
var _ proxy.Dialer = &proxyDialer{}
type proxyDialer struct {
proxyAddr string
}
func newProxyDialer(u *url.URL) proxy.Dialer {
if u.Scheme != "http" {
panic("unsupported proxy scheme")
}
return &proxyDialer{
proxyAddr: u.Host,
}
}
func (d *proxyDialer) Dial(network, addr string) (net.Conn, error) {
if network != "tcp" && network != "tcp4" && network != "tcp6" {
panic("unsupported proxy network type")
}
conn, err := net.Dial(network, d.proxyAddr) // nolint: noctx
if err != nil {
panic(err)
}
// Create a CONNECT request to the proxy with target address.
req := &http.Request{
Method: http.MethodConnect,
URL: &url.URL{Host: addr},
Header: http.Header{
"Proxy-Connection": []string{"Keep-Alive"},
},
}
err = req.Write(conn)
if err != nil {
panic(err)
}
resp, err := http.ReadResponse(bufio.NewReader(conn), req)
if err != nil {
panic(err)
}
defer func() {
if err := resp.Body.Close(); err != nil {
log.Printf("close response body: %v", err)
}
}()
if resp.StatusCode != http.StatusOK {
panic("unexpected proxy status code: " + resp.Status)
}
return conn, nil
}
func newHTTPProxy() *url.URL {
listener, err := net.Listen("tcp", "localhost:0") // nolint: noctx
if err != nil {
panic(err)
}
go func() {
for {
conn, err := listener.Accept()
if err != nil {
return
}
go proxyHandleConn(conn)
}
}()
return &url.URL{
Scheme: "http",
Host: fmt.Sprintf("localhost:%d", listener.Addr().(*net.TCPAddr).Port), // nolint:forcetypeassert
}
}
func proxyHandleConn(clientConn net.Conn) {
// Read the request from the client
req, err := http.ReadRequest(bufio.NewReader(clientConn))
if err != nil {
panic(err)
}
if req.Method != http.MethodConnect {
panic("unexpected request method: " + req.Method)
}
// Establish a connection to the target server
targetConn, err := net.Dial("tcp", req.URL.Host) // nolint:noctx,gosec
if err != nil {
panic(err)
}
// Answer to the client with a 200 OK response
if _, err := clientConn.Write([]byte("HTTP/1.1 200 OK\r\n\r\n")); err != nil {
panic(err)
}
// Copy data between client and target
go io.Copy(clientConn, targetConn) // nolint: errcheck
go io.Copy(targetConn, clientConn) // nolint: errcheck
}