// Generated by Lisette bindgen
// Source: net/http/httptest (Go stdlib)
// Go: 1.25.5
// Lisette: 0.1.20

import "go:bytes"
import "go:context"
import "go:crypto/tls"
import "go:crypto/x509"
import "go:io"
import "go:net"
import "go:net/http"

pub fn NewRecorder() -> Ref<ResponseRecorder>

/// NewRequest wraps NewRequestWithContext using context.Background.
pub fn NewRequest(method: string, target: string, body: io.Reader) -> Ref<http.Request>

/// NewRequestWithContext returns a new incoming server Request, suitable
/// for passing to an [http.Handler] for testing.
/// 
/// The target is the RFC 7230 "request-target": it may be either a
/// path or an absolute URL. If target is an absolute URL, the host name
/// from the URL is used. Otherwise, "example.com" is used.
/// 
/// The TLS field is set to a non-nil dummy value if target has scheme
/// "https".
/// 
/// The Request.Proto is always HTTP/1.1.
/// 
/// An empty method means "GET".
/// 
/// The provided body may be nil. If the body is of type [bytes.Reader],
/// [strings.Reader], [bytes.Buffer], or the value [http.NoBody],
/// the Request.ContentLength is set.
/// 
/// NewRequest panics on error for ease of use in testing, where a
/// panic is acceptable.
/// 
/// To generate a client HTTP request instead of a server request, see
/// the NewRequest function in the net/http package.
pub fn NewRequestWithContext(
  ctx: context.Context,
  method: string,
  target: string,
  body: io.Reader,
) -> Ref<http.Request>

pub fn NewServer(handler: http.Handler) -> Ref<Server>

pub fn NewTLSServer(handler: http.Handler) -> Ref<Server>

pub fn NewUnstartedServer(handler: http.Handler) -> Ref<Server>

/// ResponseRecorder is an implementation of [http.ResponseWriter] that
/// records its mutations for later inspection in tests.
pub struct ResponseRecorder {
  pub Code: int,
  pub HeaderMap: http.Header,
  pub Body: Option<Ref<bytes.Buffer>>,
  pub Flushed: bool,
}

/// A Server is an HTTP server listening on a system-chosen port on the
/// local loopback interface, for use in end-to-end HTTP tests.
pub struct Server {
  pub URL: string,
  pub Listener: Option<net.Listener>,
  pub EnableHTTP2: bool,
  pub TLS: Option<Ref<tls.Config>>,
  pub Config: Option<Ref<http.Server>>,
}

/// DefaultRemoteAddr is the default remote address to return in RemoteAddr if
/// an explicit DefaultRemoteAddr isn't set on [ResponseRecorder].
const DefaultRemoteAddr = "1.2.3.4"

impl ResponseRecorder {
  /// Flush implements [http.Flusher]. To test whether Flush was
  /// called, see rw.Flushed.
  fn Flush(self: Ref<ResponseRecorder>)

  /// Header implements [http.ResponseWriter]. It returns the response
  /// headers to mutate within a handler. To test the headers that were
  /// written after a handler completes, use the [ResponseRecorder.Result] method and see
  /// the returned Response value's Header.
  fn Header(self: Ref<ResponseRecorder>) -> http.Header

  /// Result returns the response generated by the handler.
  /// 
  /// The returned Response will have at least its StatusCode,
  /// Header, Body, and optionally Trailer populated.
  /// More fields may be populated in the future, so callers should
  /// not DeepEqual the result in tests.
  /// 
  /// The Response.Header is a snapshot of the headers at the time of the
  /// first write call, or at the time of this call, if the handler never
  /// did a write.
  /// 
  /// The Response.Body is guaranteed to be non-nil and Body.Read call is
  /// guaranteed to not return any error other than [io.EOF].
  /// 
  /// Result must only be called after the handler has finished running.
  fn Result(self: Ref<ResponseRecorder>) -> Ref<http.Response>

  /// Write implements http.ResponseWriter. The data in buf is written to
  /// rw.Body, if not nil.
  fn Write(self: Ref<ResponseRecorder>, buf: Slice<uint8>) -> Partial<int, error>

  /// WriteHeader implements [http.ResponseWriter].
  fn WriteHeader(self: Ref<ResponseRecorder>, code: int)

  /// WriteString implements [io.StringWriter]. The data in str is written
  /// to rw.Body, if not nil.
  fn WriteString(self: Ref<ResponseRecorder>, str: string) -> Result<int, error>
}

impl Server {
  /// Certificate returns the certificate used by the server, or nil if
  /// the server doesn't use TLS.
  fn Certificate(self: Ref<Server>) -> Option<Ref<x509.Certificate>>

  /// Client returns an HTTP client configured for making requests to the server.
  /// It is configured to trust the server's TLS test certificate and will
  /// close its idle connections on [Server.Close].
  /// Use Server.URL as the base URL to send requests to the server.
  fn Client(self: Ref<Server>) -> Ref<http.Client>

  /// Close shuts down the server and blocks until all outstanding
  /// requests on this server have completed.
  fn Close(self: Ref<Server>)

  /// CloseClientConnections closes any open HTTP connections to the test Server.
  fn CloseClientConnections(self: Ref<Server>)

  /// Start starts a server from NewUnstartedServer.
  fn Start(self: Ref<Server>)

  /// StartTLS starts TLS on a server from NewUnstartedServer.
  fn StartTLS(self: Ref<Server>)
}
