Trait soup::prelude::ServerExt

source ·
pub trait ServerExt: IsA<Server> + Sealed + 'static {
Show 33 methods // Provided methods fn accept_iostream( &self, stream: &impl IsA<IOStream>, local_addr: Option<&impl IsA<SocketAddress>>, remote_addr: Option<&impl IsA<SocketAddress>> ) -> Result<(), Error> { ... } fn add_auth_domain(&self, auth_domain: &impl IsA<AuthDomain>) { ... } fn add_websocket_extension(&self, extension_type: Type) { ... } fn disconnect(&self) { ... } fn listeners(&self) -> Vec<Socket> { ... } fn tls_auth_mode(&self) -> TlsAuthenticationMode { ... } fn tls_certificate(&self) -> Option<TlsCertificate> { ... } fn tls_database(&self) -> Option<TlsDatabase> { ... } fn uris(&self) -> Vec<Uri> { ... } fn is_https(&self) -> bool { ... } fn listen( &self, address: &impl IsA<SocketAddress>, options: ServerListenOptions ) -> Result<(), Error> { ... } fn listen_all( &self, port: u32, options: ServerListenOptions ) -> Result<(), Error> { ... } fn listen_local( &self, port: u32, options: ServerListenOptions ) -> Result<(), Error> { ... } fn listen_socket( &self, socket: &impl IsA<Socket>, options: ServerListenOptions ) -> Result<(), Error> { ... } fn pause_message(&self, msg: &ServerMessage) { ... } fn remove_auth_domain(&self, auth_domain: &impl IsA<AuthDomain>) { ... } fn remove_handler(&self, path: &str) { ... } fn remove_websocket_extension(&self, extension_type: Type) { ... } fn set_tls_auth_mode(&self, mode: TlsAuthenticationMode) { ... } fn set_tls_certificate(&self, certificate: &impl IsA<TlsCertificate>) { ... } fn set_tls_database(&self, tls_database: &impl IsA<TlsDatabase>) { ... } fn unpause_message(&self, msg: &ServerMessage) { ... } fn is_raw_paths(&self) -> bool { ... } fn server_header(&self) -> Option<GString> { ... } fn set_server_header(&self, server_header: Option<&str>) { ... } fn connect_request_aborted<F: Fn(&Self, &ServerMessage) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_request_finished<F: Fn(&Self, &ServerMessage) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_request_read<F: Fn(&Self, &ServerMessage) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_request_started<F: Fn(&Self, &ServerMessage) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_server_header_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_tls_auth_mode_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_tls_certificate_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_tls_database_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId { ... }
}
Expand description

Trait containing all Server methods.

§Implementors

Server

Provided Methods§

source

fn accept_iostream( &self, stream: &impl IsA<IOStream>, local_addr: Option<&impl IsA<SocketAddress>>, remote_addr: Option<&impl IsA<SocketAddress>> ) -> Result<(), Error>

Adds a new client stream to the @self.

§stream

a #GIOStream

§local_addr

the local #GSocketAddress associated with the @stream

§remote_addr

the remote #GSocketAddress associated with the @stream

§Returns

true on success, false if the stream could not be accepted or any other error occurred (in which case @error will be set).

source

fn add_auth_domain(&self, auth_domain: &impl IsA<AuthDomain>)

Adds an authentication domain to @self.

Each auth domain will have the chance to require authentication for each request that comes in; normally auth domains will require authentication for requests on certain paths that they have been set up to watch, or that meet other criteria set by the caller. If an auth domain determines that a request requires authentication (and the request doesn’t contain authentication), @self will automatically reject the request with an appropriate status (401 Unauthorized or 407 Proxy Authentication Required). If the request used the SoupServer:100-continue Expectation, @self will reject it before the request body is sent.

§auth_domain

a #SoupAuthDomain

source

fn add_websocket_extension(&self, extension_type: Type)

Add support for a WebSocket extension of the given @extension_type.

When a WebSocket client requests an extension of @extension_type, a new WebsocketExtension of type @extension_type will be created to handle the request.

Note that WebsocketExtensionDeflate is supported by default, use remove_websocket_extension() if you want to disable it.

§extension_type

a #GType

source

fn disconnect(&self)

Closes and frees @self’s listening sockets.

Note that if there are currently requests in progress on @self, that they will continue to be processed if @self’s glib::MainContext is still running.

You can call listen(), etc, after calling this function if you want to start listening again.

source

fn listeners(&self) -> Vec<Socket>

Gets @self’s list of listening sockets.

You should treat these sockets as read-only; writing to or modifiying any of these sockets may cause @self to malfunction.

§Returns

a list of listening sockets.

source

fn tls_auth_mode(&self) -> TlsAuthenticationMode

Gets the @self SSL/TLS client authentication mode.

§Returns

a #GTlsAuthenticationMode

source

fn tls_certificate(&self) -> Option<TlsCertificate>

Gets the @self SSL/TLS certificate.

§Returns

a #GTlsCertificate or None

source

fn tls_database(&self) -> Option<TlsDatabase>

Gets the @self SSL/TLS database.

§Returns

a #GTlsDatabase

source

fn uris(&self) -> Vec<Uri>

Gets a list of URIs corresponding to the interfaces @self is listening on.

These will contain IP addresses, not hostnames, and will also indicate whether the given listener is http or https.

Note that if you used listen_all() the returned URIs will use the addresses 0.0.0.0 and ::, rather than actually returning separate URIs for each interface on the system.

§Returns

a list of #GUris, which you must free when you are done with it.

source

fn is_https(&self) -> bool

Checks whether @self is capable of https.

In order for a server to run https, you must call set_tls_certificate(), or set the tls-certificate property, to provide it with a certificate to use.

If you are using the deprecated single-listener APIs, then a return value of true indicates that the #SoupServer serves https exclusively. If you are using listen(), etc, then a true return value merely indicates that the server is able to do https, regardless of whether it actually currently is or not. Use uris() to see if it currently has any https listeners.

§Returns

true if @self is configured to serve https.

source

fn listen( &self, address: &impl IsA<SocketAddress>, options: ServerListenOptions ) -> Result<(), Error>

Attempts to set up @self to listen for connections on @address.

If @options includes ServerListenOptions::HTTPS, and @self has been configured for TLS, then @self will listen for https connections on this port. Otherwise it will listen for plain http.

You may call this method (along with the other “listen” methods) any number of times on a server, if you want to listen on multiple ports, or set up both http and https service.

After calling this method, @self will begin accepting and processing connections as soon as the appropriate glib::MainContext is run.

Note that this API does not make use of dual IPv4/IPv6 sockets; if @address is an IPv6 address, it will only accept IPv6 connections. You must configure IPv4 listening separately.

§address

the address of the interface to listen on

§options

listening options for this server

§Returns

true on success, false if @address could not be bound or any other error occurred (in which case @error will be set).

source

fn listen_all( &self, port: u32, options: ServerListenOptions ) -> Result<(), Error>

Attempts to set up @self to listen for connections on all interfaces on the system.

That is, it listens on the addresses 0.0.0.0 and/or ::, depending on whether @options includes ServerListenOptions::IPV4_ONLY, ServerListenOptions::IPV6_ONLY, or neither.) If @port is specified, @self will listen on that port. If it is 0, @self will find an unused port to listen on. (In that case, you can use uris() to find out what port it ended up choosing.

See listen() for more details.

§port

the port to listen on, or 0

§options

listening options for this server

§Returns

true on success, false if @port could not be bound or any other error occurred (in which case @error will be set).

source

fn listen_local( &self, port: u32, options: ServerListenOptions ) -> Result<(), Error>

Attempts to set up @self to listen for connections on “localhost”.

That is, 127.0.0.1 and/or ::1, depending on whether @options includes ServerListenOptions::IPV4_ONLY, ServerListenOptions::IPV6_ONLY, or neither). If @port is specified, @self will listen on that port. If it is 0, @self will find an unused port to listen on. (In that case, you can use uris() to find out what port it ended up choosing.

See listen() for more details.

§port

the port to listen on, or 0

§options

listening options for this server

§Returns

true on success, false if @port could not be bound or any other error occurred (in which case @error will be set).

source

fn listen_socket( &self, socket: &impl IsA<Socket>, options: ServerListenOptions ) -> Result<(), Error>

Attempts to set up @self to listen for connections on @socket.

See listen() for more details.

§socket

a listening #GSocket

§options

listening options for this server

§Returns

true on success, false if an error occurred (in which case @error will be set).

source

fn pause_message(&self, msg: &ServerMessage)

👎Deprecated: Since 3.2

Pauses I/O on @msg.

This can be used when you need to return from the server handler without having the full response ready yet. Use unpause_message() to resume I/O.

This must only be called on a ServerMessage which was created by the #SoupServer and are currently doing I/O, such as those passed into a callback::ServerCallback or emitted in a [request-read`]crate::Server signal.

§Deprecated since 3.2

Use soup_server_message_pause() instead.

§msg

a #SoupServerMessage associated with @self.

source

fn remove_auth_domain(&self, auth_domain: &impl IsA<AuthDomain>)

Removes @auth_domain from @self.

§auth_domain

a #SoupAuthDomain

source

fn remove_handler(&self, path: &str)

Removes all handlers (early and normal) registered at @path.

§path

the toplevel path for the handler

source

fn remove_websocket_extension(&self, extension_type: Type)

Removes support for WebSocket extension of type @extension_type (or any subclass of @extension_type) from @self.

§extension_type

a #GType

source

fn set_tls_auth_mode(&self, mode: TlsAuthenticationMode)

Sets @self’s #GTlsAuthenticationMode to use for SSL/TLS client authentication.

§mode

a #GTlsAuthenticationMode

source

fn set_tls_certificate(&self, certificate: &impl IsA<TlsCertificate>)

Sets @self up to do https, using the given SSL/TLS @certificate.

§certificate

a #GTlsCertificate

source

fn set_tls_database(&self, tls_database: &impl IsA<TlsDatabase>)

Sets @self’s #GTlsDatabase to use for validating SSL/TLS client certificates.

§tls_database

a #GTlsDatabase

source

fn unpause_message(&self, msg: &ServerMessage)

👎Deprecated: Since 3.2

Resumes I/O on @msg.

Use this to resume after calling pause_message(), or after adding a new chunk to a chunked response.

I/O won’t actually resume until you return to the main loop.

This must only be called on a ServerMessage which was created by the #SoupServer and are currently doing I/O, such as those passed into a callback::ServerCallback or emitted in a [request-read`]crate::Server signal.

§Deprecated since 3.2

Use soup_server_message_unpause() instead.

§msg

a #SoupServerMessage associated with @self.

source

fn is_raw_paths(&self) -> bool

If true, percent-encoding in the Request-URI path will not be automatically decoded.

source

fn server_header(&self) -> Option<GString>

Server header.

If non-None, the value to use for the “Server” header on ServerMessages processed by this server.

The Server header is the server equivalent of the User-Agent header, and provides information about the server and its components. It contains a list of one or more product tokens, separated by whitespace, with the most significant product token coming first. The tokens must be brief, ASCII, and mostly alphanumeric (although “-”, “_”, and “.” are also allowed), and may optionally include a “/” followed by a version string. You may also put comments, enclosed in parentheses, between or after the tokens.

Some HTTP server implementations intentionally do not use version numbers in their Server header, so that installations running older versions of the server don’t end up advertising their vulnerability to specific security holes.

As with user_agent, if you set a server-header property that has trailing whitespace, #SoupServer will append its own product token (eg, libsoup/2.3.2) to the end of the header for you.

source

fn set_server_header(&self, server_header: Option<&str>)

Server header.

If non-None, the value to use for the “Server” header on ServerMessages processed by this server.

The Server header is the server equivalent of the User-Agent header, and provides information about the server and its components. It contains a list of one or more product tokens, separated by whitespace, with the most significant product token coming first. The tokens must be brief, ASCII, and mostly alphanumeric (although “-”, “_”, and “.” are also allowed), and may optionally include a “/” followed by a version string. You may also put comments, enclosed in parentheses, between or after the tokens.

Some HTTP server implementations intentionally do not use version numbers in their Server header, so that installations running older versions of the server don’t end up advertising their vulnerability to specific security holes.

As with user_agent, if you set a server-header property that has trailing whitespace, #SoupServer will append its own product token (eg, libsoup/2.3.2) to the end of the header for you.

source

fn connect_request_aborted<F: Fn(&Self, &ServerMessage) + 'static>( &self, f: F ) -> SignalHandlerId

Emitted when processing has failed for a message.

This could mean either that it could not be read (if request-read has not been emitted for it yet), or that the response could not be written back (if request-read has been emitted but request-finished has not been).

@message is in an undefined state when this signal is emitted; the signal exists primarily to allow the server to free any state that it may have allocated in request-started.

§message

the message

source

fn connect_request_finished<F: Fn(&Self, &ServerMessage) + 'static>( &self, f: F ) -> SignalHandlerId

Emitted when the server has finished writing a response to a request.

§message

the message

source

fn connect_request_read<F: Fn(&Self, &ServerMessage) + 'static>( &self, f: F ) -> SignalHandlerId

Emitted when the server has successfully read a request.

@message will have all of its request-side information filled in, and if the message was authenticated, @client will have information about that. This signal is emitted before any (non-early) handlers are called for the message, and if it sets the message’s #status_code, then normal handler processing will be skipped.

§message

the message

source

fn connect_request_started<F: Fn(&Self, &ServerMessage) + 'static>( &self, f: F ) -> SignalHandlerId

Emitted when the server has started reading a new request.

@message will be completely blank; not even the Request-Line will have been read yet. About the only thing you can usefully do with it is connect to its signals.

If the request is read successfully, this will eventually be followed by a request_read signal]. If a response is then sent, the request processing will end with a request-finished signal. If a network error occurs, the processing will instead end with request-aborted.

§message

the new message

source

fn connect_server_header_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId

source

fn connect_tls_auth_mode_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId

source

fn connect_tls_certificate_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId

source

fn connect_tls_database_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<O: IsA<Server>> ServerExt for O