// Generated by Lisette bindgen
// Source: net/http/httputil (Go stdlib)
// Go: 1.25.10
// Lisette: 0.2.1

import "go:bufio"
import "go:io"
import "go:log"
import "go:net"
import "go:net/http"
import "go:net/url"
import "go:time"

/// DumpRequest returns the given request in its HTTP/1.x wire
/// representation. It should only be used by servers to debug client
/// requests. The returned representation is an approximation only;
/// some details of the initial request are lost while parsing it into
/// an [http.Request]. In particular, the order and case of header field
/// names are lost. The order of values in multi-valued headers is kept
/// intact. HTTP/2 requests are dumped in HTTP/1.x form, not in their
/// original binary representations.
/// 
/// If body is true, DumpRequest also returns the body. To do so, it
/// consumes req.Body and then replaces it with a new [io.ReadCloser]
/// that yields the same bytes. If DumpRequest returns an error,
/// the state of req is undefined.
/// 
/// The documentation for [http.Request.Write] details which fields
/// of req are included in the dump.
pub fn DumpRequest(req: Ref<http.Request>, body: bool) -> Result<Slice<byte>, error>

/// DumpRequestOut is like [DumpRequest] but for outgoing client requests. It
/// includes any headers that the standard [http.Transport] adds, such as
/// User-Agent.
pub fn DumpRequestOut(req: Ref<http.Request>, body: bool) -> Result<Slice<byte>, error>

/// DumpResponse is like DumpRequest but dumps a response.
pub fn DumpResponse(resp: Ref<http.Response>, body: bool) -> Result<Slice<byte>, error>

/// NewChunkedReader returns a new chunkedReader that translates the data read from r
/// out of HTTP "chunked" format before returning it.
/// The chunkedReader returns [io.EOF] when the final 0-length chunk is read.
/// 
/// NewChunkedReader is not needed by normal applications. The http package
/// automatically decodes chunking when reading response bodies.
pub fn NewChunkedReader(r: io.Reader) -> io.Reader

/// NewChunkedWriter returns a new chunkedWriter that translates writes into HTTP
/// "chunked" format before writing them to w. Closing the returned chunkedWriter
/// sends the final 0-length chunk that marks the end of the stream but does
/// not send the final CRLF that appears after trailers; trailers and the last
/// CRLF must be written separately.
/// 
/// NewChunkedWriter is not needed by normal applications. The http
/// package adds chunking automatically if handlers don't set a
/// Content-Length header. Using NewChunkedWriter inside a handler
/// would result in double chunking or chunking with a Content-Length
/// length, both of which are wrong.
pub fn NewChunkedWriter(w: io.Writer) -> io.WriteCloser

/// NewClientConn is an artifact of Go's early HTTP implementation.
/// It is low-level, old, and unused by Go's current HTTP stack.
/// We should have deleted it before Go 1.
/// 
/// Deprecated: Use the Client or Transport in package [net/http] instead.
pub fn NewClientConn(c: net.Conn, r: Ref<bufio.Reader>) -> Ref<ClientConn>

/// NewProxyClientConn is an artifact of Go's early HTTP implementation.
/// It is low-level, old, and unused by Go's current HTTP stack.
/// We should have deleted it before Go 1.
/// 
/// Deprecated: Use the Client or Transport in package [net/http] instead.
pub fn NewProxyClientConn(c: net.Conn, r: Ref<bufio.Reader>) -> Ref<ClientConn>

/// NewServerConn is an artifact of Go's early HTTP implementation.
/// It is low-level, old, and unused by Go's current HTTP stack.
/// We should have deleted it before Go 1.
/// 
/// Deprecated: Use the Server in package [net/http] instead.
pub fn NewServerConn(c: net.Conn, r: Ref<bufio.Reader>) -> Ref<ServerConn>

/// NewSingleHostReverseProxy returns a new [ReverseProxy] that routes
/// URLs to the scheme, host, and base path provided in target. If the
/// target's path is "/base" and the incoming request was for "/dir",
/// the target request will be for /base/dir.
/// 
/// NewSingleHostReverseProxy does not rewrite the Host header.
/// 
/// To customize the ReverseProxy behavior beyond what
/// NewSingleHostReverseProxy provides, use ReverseProxy directly
/// with a Rewrite function. The ProxyRequest SetURL method
/// may be used to route the outbound request. (Note that SetURL,
/// unlike NewSingleHostReverseProxy, rewrites the Host header
/// of the outbound request by default.)
/// 
/// 	proxy := &ReverseProxy{
/// 		Rewrite: func(r *ProxyRequest) {
/// 			r.SetURL(target)
/// 			r.Out.Host = r.In.Host // if desired
/// 		},
/// 	}
pub fn NewSingleHostReverseProxy(target: Ref<url.URL>) -> Ref<ReverseProxy>

/// A BufferPool is an interface for getting and returning temporary
/// byte slices for use by [io.CopyBuffer].
pub interface BufferPool {
  fn Get() -> Slice<byte>
  fn Put(b: Slice<byte>)
}

/// ClientConn is an artifact of Go's early HTTP implementation.
/// It is low-level, old, and unused by Go's current HTTP stack.
/// We should have deleted it before Go 1.
/// 
/// Deprecated: Use Client or Transport in package [net/http] instead.
pub type ClientConn

/// A ProxyRequest contains a request to be rewritten by a [ReverseProxy].
pub struct ProxyRequest {
  pub In: Option<Ref<http.Request>>,
  pub Out: Option<Ref<http.Request>>,
}

/// ReverseProxy is an HTTP Handler that takes an incoming request and
/// sends it to another server, proxying the response back to the
/// client.
/// 
/// 1xx responses are forwarded to the client if the underlying
/// transport supports ClientTrace.Got1xxResponse.
/// 
/// Hop-by-hop headers (see RFC 9110, section 7.6.1), including
/// Connection, Proxy-Connection, Keep-Alive, Proxy-Authenticate,
/// Proxy-Authorization, TE, Trailer, Transfer-Encoding, and Upgrade,
/// are removed from client requests and backend responses.
/// The Rewrite function may be used to add hop-by-hop headers to the request,
/// and the ModifyResponse function may be used to remove them from the response.
pub struct ReverseProxy {
  pub Rewrite: Option<fn(Ref<ProxyRequest>) -> ()>,
  pub Director: Option<fn(Ref<http.Request>) -> ()>,
  pub Transport: Option<http.RoundTripper>,
  pub FlushInterval: time.Duration,
  pub ErrorLog: Option<Ref<log.Logger>>,
  pub BufferPool: Option<BufferPool>,
  pub ModifyResponse: Option<fn(Ref<http.Response>) -> Result<(), error>>,
  pub ErrorHandler: Option<fn(http.ResponseWriter, Ref<http.Request>, error) -> ()>,
}

/// ServerConn is an artifact of Go's early HTTP implementation.
/// It is low-level, old, and unused by Go's current HTTP stack.
/// We should have deleted it before Go 1.
/// 
/// Deprecated: Use the Server in package [net/http] instead.
pub type ServerConn

pub var ErrClosed: Ref<http.ProtocolError>

/// ErrLineTooLong is returned when reading malformed chunked data
/// with lines that are too long.
pub var ErrLineTooLong: error

pub var ErrPersistEOF: Ref<http.ProtocolError>

pub var ErrPipeline: Ref<http.ProtocolError>

impl ClientConn {
  /// Close calls [ClientConn.Hijack] and then also closes the underlying connection.
  #[allow(unused_result)]
  fn Close(self: Ref<ClientConn>) -> Result<(), error>

  /// Do is convenience method that writes a request and reads a response.
  fn Do(self: Ref<ClientConn>, req: Ref<http.Request>) -> Result<Ref<http.Response>, error>

  /// Hijack detaches the [ClientConn] and returns the underlying connection as well
  /// as the read-side bufio which may have some left over data. Hijack may be
  /// called before the user or Read have signaled the end of the keep-alive
  /// logic. The user should not call Hijack while [ClientConn.Read] or ClientConn.Write is in progress.
  fn Hijack(self: Ref<ClientConn>) -> (net.Conn, Ref<bufio.Reader>)

  /// Pending returns the number of unanswered requests
  /// that have been sent on the connection.
  fn Pending(self: Ref<ClientConn>) -> int

  /// Read reads the next response from the wire. A valid response might be
  /// returned together with an [ErrPersistEOF], which means that the remote
  /// requested that this be the last request serviced. Read can be called
  /// concurrently with [ClientConn.Write], but not with another Read.
  fn Read(self: Ref<ClientConn>, req: Ref<http.Request>) -> Result<Ref<http.Response>, error>

  /// Write writes a request. An [ErrPersistEOF] error is returned if the connection
  /// has been closed in an HTTP keep-alive sense. If req.Close equals true, the
  /// keep-alive connection is logically closed after this request and the opposing
  /// server is informed. An ErrUnexpectedEOF indicates the remote closed the
  /// underlying TCP connection, which is usually considered as graceful close.
  fn Write(self: Ref<ClientConn>, req: Ref<http.Request>) -> Result<(), error>
}

impl ProxyRequest {
  /// SetURL routes the outbound request to the scheme, host, and base path
  /// provided in target. If the target's path is "/base" and the incoming
  /// request was for "/dir", the target request will be for "/base/dir".
  /// To route requests without joining the incoming path,
  /// set r.Out.URL directly.
  /// 
  /// SetURL rewrites the outbound Host header to match the target's host.
  /// To preserve the inbound request's Host header (the default behavior
  /// of [NewSingleHostReverseProxy]):
  /// 
  /// 	rewriteFunc := func(r *httputil.ProxyRequest) {
  /// 		r.SetURL(url)
  /// 		r.Out.Host = r.In.Host
  /// 	}
  fn SetURL(self: Ref<ProxyRequest>, target: Ref<url.URL>)

  /// SetXForwarded sets the X-Forwarded-For, X-Forwarded-Host, and
  /// X-Forwarded-Proto headers of the outbound request.
  /// 
  ///   - The X-Forwarded-For header is set to the client IP address.
  ///   - The X-Forwarded-Host header is set to the host name requested
  ///     by the client.
  ///   - The X-Forwarded-Proto header is set to "http" or "https", depending
  ///     on whether the inbound request was made on a TLS-enabled connection.
  /// 
  /// If the outbound request contains an existing X-Forwarded-For header,
  /// SetXForwarded appends the client IP address to it. To append to the
  /// inbound request's X-Forwarded-For header (the default behavior of
  /// [ReverseProxy] when using a Director function), copy the header
  /// from the inbound request before calling SetXForwarded:
  /// 
  /// 	rewriteFunc := func(r *httputil.ProxyRequest) {
  /// 		r.Out.Header["X-Forwarded-For"] = r.In.Header["X-Forwarded-For"]
  /// 		r.SetXForwarded()
  /// 	}
  fn SetXForwarded(self: Ref<ProxyRequest>)
}

impl ReverseProxy {
  fn ServeHTTP(
    self: Ref<ReverseProxy>,
    rw: http.ResponseWriter,
    req: Ref<http.Request>,
  )
}

impl ServerConn {
  /// Close calls [ServerConn.Hijack] and then also closes the underlying connection.
  #[allow(unused_result)]
  fn Close(self: Ref<ServerConn>) -> Result<(), error>

  /// Hijack detaches the [ServerConn] and returns the underlying connection as well
  /// as the read-side bufio which may have some left over data. Hijack may be
  /// called before Read has signaled the end of the keep-alive logic. The user
  /// should not call Hijack while [ServerConn.Read] or [ServerConn.Write] is in progress.
  fn Hijack(self: Ref<ServerConn>) -> (net.Conn, Ref<bufio.Reader>)

  /// Pending returns the number of unanswered requests
  /// that have been received on the connection.
  fn Pending(self: Ref<ServerConn>) -> int

  /// Read returns the next request on the wire. An [ErrPersistEOF] is returned if
  /// it is gracefully determined that there are no more requests (e.g. after the
  /// first request on an HTTP/1.0 connection, or after a Connection:close on a
  /// HTTP/1.1 connection).
  fn Read(self: Ref<ServerConn>) -> Result<Ref<http.Request>, error>

  /// Write writes resp in response to req. To close the connection gracefully, set the
  /// Response.Close field to true. Write should be considered operational until
  /// it returns an error, regardless of any errors returned on the [ServerConn.Read] side.
  fn Write(
    self: Ref<ServerConn>,
    req: Ref<http.Request>,
    resp: Ref<http.Response>,
  ) -> Result<(), error>
}
