Updated workbook content.

cosmetic.
This commit is contained in:
Jocelyn Fiat
2017-02-15 17:49:31 +01:00
parent fa2fa6f35c
commit 94f3c3b849
6 changed files with 594 additions and 590 deletions

View File

@@ -38,7 +38,7 @@ title: Getting started
<li>located in <i>$ISE_EIFFEL/contrib/examples/web/ewf</i></li> <li>located in <i>$ISE_EIFFEL/contrib/examples/web/ewf</i></li>
<li><a href="https://github.com/EiffelWebFramework/ewf_examples">available on Github</a></li> <li><a href="https://github.com/EiffelWebFramework/ewf_examples">available on Github</a></li>
</ul> </ul>
<li>Read the <a href="{{ site.url }}/workbook/readme">Overview</a></li> <li>Read the <a href="{{ site.url }}/workbook/workbook">Overview</a></li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@@ -54,7 +54,7 @@ The status line consists of the HTTP version (HTTP/1.1 in the preceding example)
## How to set the status code ## How to set the status code
If you need to set an arbitrary status code, you can use the ```WSF_RESPONSE.put_header``` feature or the ```WSF_RESPONSE.set_status_code``` feature. An status code of 200 is a default value. See below examples using the mentioned features. If you need to set an arbitrary status code, you can use the `WSF_RESPONSE.put_header` feature or the `WSF_RESPONSE.set_status_code` feature. An status code of 200 is a default value. See below examples using the mentioned features.
### Using the WSF_RESPONSE.put_header feature. ### Using the WSF_RESPONSE.put_header feature.
In this case you provide the status code with a collection of headers. In this case you provide the status code with a collection of headers.
@@ -79,7 +79,7 @@ Example
### Using the WSF_RESPONSE.set_status code ### Using the WSF_RESPONSE.set_status code
```eiffel ```eiffel
custom_response (req: WSF_REQUEST; res: WSF_RESPONSE; output: STRING) custom_response (req: WSF_REQUEST; res: WSF_RESPONSE; output: STRING)
local local
h: HTTP_HEADER h: HTTP_HEADER
l_msg: STRING l_msg: STRING
@@ -94,12 +94,13 @@ Example
res.put_string (l_msg) res.put_string (l_msg)
end end
``` ```
Both features takes an INTEGER (the status code) as an formal argument, you can use 200, 300, 500 etc directly, but instead of using explicit numbers, it's recommended to use the constants defined in the class `HTTP_STATUS_CODE`. The name of each constant is based from the standard [HTTP 1.1](https://httpwg.github.io/). Both features takes an INTEGER (the status code) as an formal argument, you can use 200, 300, 500 etc directly, but instead of using explicit numbers, it's recommended to use the constants defined in the class `HTTP_STATUS_CODE`. The name of each constant is based from the standard [HTTP 1.1](https://httpwg.github.io/).
<a name="redirect"></a> <a name="redirect"></a>
## How to redirect to a particular location. ## How to redirect to a particular location.
To redirect the response to a new location, we need to send a 302 status code, to do that we use ```{HTTP_STATUS_CODE}.found``` To redirect the response to a new location, we need to send a 302 status code, to do that we use `{HTTP_STATUS_CODE}.found`
> The 302 (Found) status code indicates that the target resource resides temporarily under a different URI. Since the redirection might be altered on occasion, the client ought to continue to use the effective request URI for future requests. > The 302 (Found) status code indicates that the target resource resides temporarily under a different URI. Since the redirection might be altered on occasion, the client ought to continue to use the effective request URI for future requests.
@@ -110,7 +111,7 @@ Another way to do redirection is with 303 status code
The next code show a custom feature to write a redirection, you can use found or see_other based on your particular requirements. The next code show a custom feature to write a redirection, you can use found or see_other based on your particular requirements.
```eiffel ```eiffel
send_redirect (req: WSF_REQUEST; res: WSF_RESPONSE; a_location: READABLE_STRING_32) send_redirect (req: WSF_REQUEST; res: WSF_RESPONSE; a_location: READABLE_STRING_32)
-- Redirect to `a_location' -- Redirect to `a_location'
local local
h: HTTP_HEADER h: HTTP_HEADER
@@ -127,23 +128,23 @@ The next code show a custom feature to write a redirection, you can use found or
The class `WSF_RESPONSE` provide features to work with redirection The class `WSF_RESPONSE` provide features to work with redirection
```eiffel ```eiffel
redirect_now (a_url: READABLE_STRING_8) redirect_now (a_url: READABLE_STRING_8)
-- Redirect to the given url `a_url' -- Redirect to the given url `a_url'
require require
header_not_committed: not header_committed header_not_committed: not header_committed
redirect_now_custom (a_url: READABLE_STRING_8; a_status_code: INTEGER_32; a_header: detachable HTTP_HEADER; a_content: detachable TUPLE [body: READABLE_STRING_8; type: READABLE_STRING_8]) redirect_now_custom (a_url: READABLE_STRING_8; a_status_code: INTEGER_32; a_header: detachable HTTP_HEADER; a_content: detachable TUPLE [body: READABLE_STRING_8; type: READABLE_STRING_8])
-- Redirect to the given url `a_url' and precise custom `a_status_code', custom header and content -- Redirect to the given url `a_url' and precise custom `a_status_code', custom header and content
-- Please see http://www.faqs.org/rfcs/rfc2616 to use proper status code. -- Please see http://www.faqs.org/rfcs/rfc2616 to use proper status code.
-- if `a_status_code' is 0, use the default {HTTP_STATUS_CODE}.temp_redirect -- if `a_status_code' is 0, use the default {HTTP_STATUS_CODE}.temp_redirect
require require
header_not_committed: not header_committed header_not_committed: not header_committed
redirect_now_with_content (a_url: READABLE_STRING_8; a_content: READABLE_STRING_8; a_content_type: READABLE_STRING_8) redirect_now_with_content (a_url: READABLE_STRING_8; a_content: READABLE_STRING_8; a_content_type: READABLE_STRING_8)
-- Redirect to the given url `a_url' -- Redirect to the given url `a_url'
``` ```
The ```WSF_RESPONSE.redirect_now``` feature use the status code ```{HTTP_STATUS_CODE}.found```,the other redirect features enable customize the status code and content based on your requirements. The `WSF_RESPONSE.redirect_now` feature use the status code `{HTTP_STATUS_CODE}.found`,the other redirect features enable customize the status code and content based on your requirements.
Using a similar approach we can build features to answer a bad request (400), internal server error (500), etc. We will build a simple example showing the most common HTTP status codes. Using a similar approach we can build features to answer a bad request (400), internal server error (500), etc. We will build a simple example showing the most common HTTP status codes.
@@ -154,19 +155,22 @@ Using a similar approach we can build features to answer a bad request (400), in
The status-code element is a three-digit integer code giving the result of the attempt to understand and satisfy the request. The first digit of the status-code defines the class of response. The status-code element is a three-digit integer code giving the result of the attempt to understand and satisfy the request. The first digit of the status-code defines the class of response.
General categories: General categories:
* [1xx](https://httpwg.github.io/specs/rfc7231.html#status.1xx) Informational: The 1xx series of response codes are used only in negotiations with the HTTP server. * [1xx](https://httpwg.github.io/specs/rfc7231.html#status.1xx) Informational: The 1xx series of response codes are used only in negotiations with the HTTP server.
* [2xx](https://httpwg.github.io/specs/rfc7231.html#status.2xx) Sucessful: The 2xx error codes indicate that an operation was successful. * [2xx](https://httpwg.github.io/specs/rfc7231.html#status.2xx) Sucessful: The 2xx error codes indicate that an operation was successful.
* [3xx](https://httpwg.github.io/specs/rfc7231.html#status.3xx) Redirection: The 3xx status codes indicate that the client needs to do some extra work to get what it wants. * [3xx](https://httpwg.github.io/specs/rfc7231.html#status.3xx) Redirection: The 3xx status codes indicate that the client needs to do some extra work to get what it wants.
* [4xx](https://httpwg.github.io/specs/rfc7231.html#status.4xx) Client Error: These status codes indicate that something is wrong on the client side. * [4xx](https://httpwg.github.io/specs/rfc7231.html#status.4xx) Client Error: These status codes indicate that something is wrong on the client side.
* [5xx](https://httpwg.github.io/specs/rfc7231.html#status.5xx) Server Error: These status codes indicate that something is wrong on the server side. * [5xx](https://httpwg.github.io/specs/rfc7231.html#status.5xx) Server Error: These status codes indicate that something is wrong on the server side.
Note: use ```res.set_status_code({HTTP_STATUS_CODE}.bad_request)``` rather than ```res.set_status_code(400)```. Note: use `res.set_status_code({HTTP_STATUS_CODE}.bad_request)` rather than `res.set_status_code(400)`.
<a name="example_1"></a> <a name="example_1"></a>
### Example Staus Codes ### Example Staus Codes
Basic Service that builds a simple web page to show the most common status codes Basic Service that builds a simple web page to show the most common status codes
```eiffel ```eiffel
class class
APPLICATION_EXECUTION APPLICATION_EXECUTION
@@ -484,7 +488,8 @@ end
Using cURL to test the application Using cURL to test the application
--- ---
In the first call we use the ```res.redirect_now (l_engine_url)``` feature In the first call we use the `res.redirect_now (l_engine_url)` feature
``` ```
#>curl -i -H -v -X POST -d "query=Eiffel&engine=Google" http://localhost:9090/search #>curl -i -H -v -X POST -d "query=Eiffel&engine=Google" http://localhost:9090/search
HTTP/1.1 302 Found HTTP/1.1 302 Found
@@ -533,7 +538,6 @@ Connection: close
</html> </html>
``` ```
#### Missing query form parameter #### Missing query form parameter
``` ```
@@ -602,8 +606,8 @@ The response header fields allow the server to pass additional information about
### How to set response headers. ### How to set response headers.
HTTP allows multiple occurrences of the same header name, the features ```put_XYZ``` replace existing headers with the same name and HTTP allows multiple occurrences of the same header name, the features `put_XYZ` replace existing headers with the same name and
features ```add_XYZ``` add headers that can lead to duplicated entries. features `add_XYZ` add headers that can lead to duplicated entries.
```eiffel ```eiffel

View File

@@ -1,4 +1,4 @@
The [Workbook](workbook) lets you discover the EiffelWeb framework. The [Workbook](./workbook.md) lets you discover the EiffelWeb framework.
[Enter the documentation](workbook) [Enter the documentation](./workbook.md)

View File

@@ -43,7 +43,7 @@ Before reading (or walking throught) the workbook, to get a quick overview of EW
<a name="wui"></a> <a name="wui"></a>
## Web User Interface ## Web User Interface
[Web User Interface](./wui/readme.md) [Web User Interface](./wui/wui.md)
<a name="handling_cookies"></a> <a name="handling_cookies"></a>
@@ -53,4 +53,4 @@ Before reading (or walking throught) the workbook, to get a quick overview of EW
<a name="deployment"></a> <a name="deployment"></a>
## EWF Deployment ## EWF Deployment
[EWF Deployment](./deployment/readme.md) [EWF Deployment](./deployment/deployment.md)