|
|
|
|
@@ -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
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
In this case you provide the status code with a collection of headers.
|
|
|
|
|
@@ -94,12 +94,13 @@ Example
|
|
|
|
|
res.put_string (l_msg)
|
|
|
|
|
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/).
|
|
|
|
|
|
|
|
|
|
<a name="redirect"></a>
|
|
|
|
|
|
|
|
|
|
## 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.
|
|
|
|
|
|
|
|
|
|
@@ -143,7 +144,7 @@ The class `WSF_RESPONSE` provide features to work with redirection
|
|
|
|
|
-- 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.
|
|
|
|
|
@@ -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.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
* [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.
|
|
|
|
|
* [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.
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
|
|
### Example Staus Codes
|
|
|
|
|
|
|
|
|
|
Basic Service that builds a simple web page to show the most common status codes
|
|
|
|
|
|
|
|
|
|
```eiffel
|
|
|
|
|
class
|
|
|
|
|
APPLICATION_EXECUTION
|
|
|
|
|
@@ -484,7 +488,8 @@ end
|
|
|
|
|
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
|
|
|
|
|
HTTP/1.1 302 Found
|
|
|
|
|
@@ -533,7 +538,6 @@ Connection: close
|
|
|
|
|
</html>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### 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.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```eiffel
|
|
|
|
|
|