diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-06-15 12:50:03 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-06-15 13:39:29 -0700 |
| commit | 5ecea06b1f39a93735e8b2f711b125d0b1a84d16 (patch) | |
| tree | 843c699c3618328856c0b373a4b49b75205bf234 /docs/man | |
| parent | 16088417694de3d3300ae8429c20e944128d3f52 (diff) | |
| download | nng-5ecea06b1f39a93735e8b2f711b125d0b1a84d16.tar.gz nng-5ecea06b1f39a93735e8b2f711b125d0b1a84d16.tar.bz2 nng-5ecea06b1f39a93735e8b2f711b125d0b1a84d16.zip | |
fixes #539 Feature request: customizable http error page
Diffstat (limited to 'docs/man')
| -rw-r--r-- | docs/man/libnng.3.adoc | 3 | ||||
| -rw-r--r-- | docs/man/nng_http_server_res_error.3http.adoc | 63 | ||||
| -rw-r--r-- | docs/man/nng_http_server_set_error_file.3http.adoc | 73 | ||||
| -rw-r--r-- | docs/man/nng_http_server_set_error_page.3http.adoc | 69 |
4 files changed, 208 insertions, 0 deletions
diff --git a/docs/man/libnng.3.adoc b/docs/man/libnng.3.adoc index 21a34a6a..70fd3be2 100644 --- a/docs/man/libnng.3.adoc +++ b/docs/man/libnng.3.adoc @@ -341,7 +341,10 @@ These functions are intended for use with HTTP server applications. |<<nng_http_server_get_tls.3http#,nng_http_server_get_tls()>>|get HTTP server TLS configuration |<<nng_http_server_hold.3http#,nng_http_server_get_tls()>>|get and hold HTTP server instance |<<nng_http_server_release.3http#,nng_http_server_get_tls()>>|release HTTP server instance +|<<nng_http_server_set_error_file.3http#,nng_http_server_set_error_file()>>|set custom HTTP error file +|<<nng_http_server_set_error_page.3http#,nng_http_server_set_error_page()>>|set custom HTTP error page |<<nng_http_server_set_tls.3http#,nng_http_server_set_tls()>>|set HTTP server TLS configuration +|<<nng_http_server_res_error.3http#,nng_http_server_res_error()>>|use HTTP server error page |<<nng_http_server_start.3http#,nng_http_server_start()>>|start HTTP server |<<nng_http_server_stop.3http#,nng_http_server_stop()>>|stop HTTP server |=== diff --git a/docs/man/nng_http_server_res_error.3http.adoc b/docs/man/nng_http_server_res_error.3http.adoc new file mode 100644 index 00000000..a62628f7 --- /dev/null +++ b/docs/man/nng_http_server_res_error.3http.adoc @@ -0,0 +1,63 @@ += nng_http_server_res_error(3http) +// +// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2018 Capitar IT Group BV <info@capitar.com> +// +// This document is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +== NAME + +nng_http_server_res_error - use HTTP server error page + +== SYNOPSIS + +[source, c] +---- +#include <nng/nng.h> +#include <nng/supplemental/http/http.h> + +int nng_http_server_set_error_file(nng_http_server *server, + nng_http_res *response); +---- + +== DESCRIPTION + +The `nng_http_server_res_error()` sets the body of _response_ +to _server_'s error page, which may have been customized using the +`<<nng_http_server_set_error_file.3http#,nng_http_server_error_file()>>` +or +`<<nng_http_server_set_error_page.3http#,nng_http_server_error_page()>>` +functions. + +The status code of the _response_ should have already been set, either +implicitly by allocating it with +`<<nng_http_res_alloc_error.3http#,nng_http_res_alloc_error()>>`, +or by calling +`<<nng_http_res_set_status.3http#,nng_http_res_set_status()>>`. + +Any content body previously set for _response_ will be overridden by +this function. + +== RETURN VALUES + +This function returns 0 on success, and non-zero otherwise. + +== ERRORS + +[horizontal] +`NNG_ENOMEM`:: Insufficient free memory exists. +`NNG_ENOTSUP`:: HTTP not supported. + +== SEE ALSO + +[.text-left] +<<nng_http_res_alloc_error.3http#,nng_http_res_alloc_error(3http)>>, +<<nng_http_server_hold.3http#,nng_http_server_hold(3http)>>, +<<nng_http_server_set_error_file.3http#,nng_http_server_set_error_file(3http)>>, +<<nng_http_server_set_error_page.3http#,nng_http_server_set_error_page(3http)>>, +<<nng_strerror.3#,nng_strerror(3)>>, +<<nng.7#,nng(7)>> diff --git a/docs/man/nng_http_server_set_error_file.3http.adoc b/docs/man/nng_http_server_set_error_file.3http.adoc new file mode 100644 index 00000000..dde8d980 --- /dev/null +++ b/docs/man/nng_http_server_set_error_file.3http.adoc @@ -0,0 +1,73 @@ += nng_http_server_set_error_file(3http) +// +// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2018 Capitar IT Group BV <info@capitar.com> +// +// This document is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +== NAME + +nng_http_server_set_error_file - set custom HTTP error file + +== SYNOPSIS + +[source, c] +---- +#include <nng/nng.h> +#include <nng/supplemental/http/http.h> + +int nng_http_server_set_error_file(nng_http_server *server, + uint16_t code, const char *path); +---- + +== DESCRIPTION + +The `nng_http_server_set_error_file()` sets an error page to be used +for HTTP status _code_ on the server instance _server_. +The body content of the HTTP responses will contain the file contents of +the file located at _path_, which should be an HTML file. + +The custom HTML content will be used when the server is returning an +internally generated error response, or is returning an error response +that was allocated with the +`<<nng_http_res_alloc_error.3http#,nng_http_res_alloc_error()>>` +function. +This HTML content will also be used if the application calls the +`<<nng_http_server_res_error.3http#,nng_http_server_res_error()>>`. +The last custom error page set for _code_ by either this function or +`<<nng_http_server_set_error_page.3http#,nng_http_server_error_page()>>` +will be used. + +NOTE: Error responses that have their body content changed after allocation, +or that are written directly by the application, will not use the body +content supplied here. + +NOTE: The file contents of _path_ are read when this function is called. +Therefore, if the file contents are changed, then this function should +be called again to update the error page. + +== RETURN VALUES + +This function returns 0 on success, and non-zero otherwise. + +== ERRORS + +[horizontal] +`NNG_ENOENT`:: The file named by _path_ does not exist. +`NNG_EPERM`:: No permission to read the file named by _path_. +`NNG_ENOMEM`:: Insufficient free memory exists. +`NNG_ENOTSUP`:: HTTP not supported. + +== SEE ALSO + +[.text-left] +<<nng_http_res_alloc_error.3http#,nng_http_res_alloc_error(3http)>>, +<<nng_http_server_hold.3http#,nng_http_server_hold(3http)>>, +<<nng_http_server_res_error.3http#,nng_http_server_res_error(3http)>>, +<<nng_http_server_set_error_page.3http#,nng_http_server_set_error_page(3http)>>, +<<nng_strerror.3#,nng_strerror(3)>>, +<<nng.7#,nng(7)>> diff --git a/docs/man/nng_http_server_set_error_page.3http.adoc b/docs/man/nng_http_server_set_error_page.3http.adoc new file mode 100644 index 00000000..271b9d99 --- /dev/null +++ b/docs/man/nng_http_server_set_error_page.3http.adoc @@ -0,0 +1,69 @@ += nng_http_server_set_error_page(3http) +// +// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2018 Capitar IT Group BV <info@capitar.com> +// +// This document is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +== NAME + +nng_http_server_set_error_page - set custom HTTP error page + +== SYNOPSIS + +[source, c] +---- +#include <nng/nng.h> +#include <nng/supplemental/http/http.h> + +int nng_http_server_set_error_page(nng_http_server *server, + uint16_t code, const char *html); +---- + +== DESCRIPTION + +The `nng_http_server_set_error_page()` sets an error page to be used +for HTTP status _code_ on the server instance _server_. +The body content of the HTTP responses will contain _html_. + +The custom HTML content will be used when the server is returning an +internally generated error response, or is returning an error response +that was allocated with the +`<<nng_http_res_alloc_error.3http#,nng_http_res_alloc_error()>>` +function. +This HTML content will also be used if the application calls the +`<<nng_http_server_res_error.3http#,nng_http_server_res_error()>>`. +The last custom error page set for _code_ by either this function or +`<<nng_http_server_set_error_file.3http#,nng_http_server_error_file()>>` +will be used. + +NOTE: Error responses that have their body content changed after allocation, +or that are written directly by the application, will not use the body +content supplied here. + +The supplied HTML content is copied by this function, and may be reused +after this function returns. + +== RETURN VALUES + +This function returns 0 on success, and non-zero otherwise. + +== ERRORS + +[horizontal] +`NNG_ENOMEM`:: Insufficient free memory exists. +`NNG_ENOTSUP`:: HTTP not supported. + +== SEE ALSO + +[.text-left] +<<nng_http_res_alloc_error.3http#,nng_http_res_alloc_error(3http)>>, +<<nng_http_server_hold.3http#,nng_http_server_hold(3http)>>, +<<nng_http_server_res_error.3http#,nng_http_server_res_error(3http)>>, +<<nng_http_server_set_error_file.3http#,nng_http_server_set_error_file(3http)>>, +<<nng_strerror.3#,nng_strerror(3)>>, +<<nng.7#,nng(7)>> |
