You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/references/parson.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,11 +68,11 @@ struct json_array_t {
68
68
};
69
69
```
70
70
71
-
In OOPS terms,`JSON_Value`is like a generic `Base Class` and `JSON_Object` and `JSON_Array`are like `Derived Class` objects.
71
+
You can assume`JSON_Value`as a generic *Base Class* and `JSON_Object` and `JSON_Array`as it's *Derived Class* objects.
72
72
73
73
## JSON_Value Methods
74
74
75
-
### `json_parse_file`
75
+
### `json_parse_file()`
76
76
Reads a JSON file and returns (`JSON_Value*`) that contains the entire content.
77
77
78
78
```c
@@ -90,7 +90,7 @@ So after getting the `JSON_Value` struct object from `json_parse_file()`, method
90
90
Since a JSON file can start with any valid data type (an object, an array, a string, or a number), the parser returns a generic `JSON_Value` struct object. We then must use the appropriate method to resolve it into the intended object or array.
91
91
:::
92
92
93
-
### `json_value_get_object`
93
+
### `json_value_get_object()`
94
94
95
95
Gets the main `JSON_Object` from a `JSON_Value`. Since our `xps_config.json` starts with `{}` we can use this function. If it had been starting with `[]` then that would imply the file starts as an array of object so we would have to use `json_value_get_array()` instead.
- HTTP is case insensitive. Modify the code such that the comparison handles input key in a case insensitive way.
789
-
:::
788
+
- TTP header names are case insensitive. Modify the code such that the comparison handles the input key in a case insensitive way.
789
+
790
+
:::
790
791
791
792
- **`xps_http_serialize_headers()`**
792
793
793
-
Serialize a list of HTTP headers(key-value pairs) into a buffer. The serialized headers will be formatted as a string, where each header is in the format - key: value\n. The function `sprintf` is used to format and store a string into a character buffer.
794
+
Serialize a list of HTTP headers(key-value pairs) into a buffer. The serialized headers will be formatted as a string, where each header is in the format - `key: value\n`. The function `sprintf` is used to format and store a string into a character buffer.
794
795
For each key value pair (eg. given below), an additional size of +5 characters are added to account for the colon (`:`), space (` `), newline (`\r\n`), and null terminator (`\0`).
`xps_http_res_serialize()` : used for serializing the whole response into a buffer. It is similiar to the serialize function used in http_request module.
150
150
151
-
- First the headers are serialized using `xps_http_res_serialize()` , provided in the `xps_http` module and are stored into a temporary buffer.
151
+
- First the headers are serialized using `xps_http_serialize_headers()` , provided in the `xps_http` module and are stored into a temporary buffer.
152
152
- Then create a buffer instance for storing the serialized HTTP response. The length of the buffer is calculated by adding the lengths of each field in the struct `xps_http_res_s`.
153
153
- Copy the response_line, header and body to the newly created buffer. Don’t forget to include a newline between response_line, headers and body.
- `xps_config_destroy` : Cleans up and frees the memory allocated for the configuration object. Implement it by deallocating the servers and the corresponding listeners and routes. Also de-initialize the vectors.
280
-
- `xps_config_lookup` : Performs a lookup to find the correct configuration based on an HTTP request (`xps_http_req_t`) and client details (`xps_connection_t`).
281
+
- `xps_config_lookup` : Takes the parsed configuration, an incoming HTTP request, and the client connection as input. It determines the appropriate server and route for the request by first matching the client's listener and hostname against the configured servers, then selecting the best matching route using a longest prefix match on the request path. Based on the matched route type (`file_serve`, `reverse_proxy`, or `redirect`), it populates and returns an `xps_config_lookup_t` structure with the relevant fields. Sets `*error` to `E_FAIL` or `E_NOTFOUND` and returns `NULL` if no matching server or route is found.
- To `xps_core_s` struct, add `config` field. `xps_core_create()` takes config as argument.
387
-
- Remove creating listeners while starting the server as the listeners are created during the configuration set-up itself.
387
+
- To `xps_core_s` struct, add `config` field. Pass `config`as an argument to `xps_core_create()`.
388
+
- Remove creating listeners while starting the server as the listeners are created during the configuration set-up itself (this will be done below, on modification to the `main.c`).
388
389
389
390
### Session Module - Modifications
390
391
391
-
- Add the lookup field which is used to determine the type of the incoming request.
392
-
- In the `session_process_request()` the lookup(to determine the type of request) is done and the request is processed with respect to its type.
392
+
- Add a lookup field (`xps_config_lookup_t`) which is used to determine the type of the incoming request.
393
+
- In the `session_process_request()` the lookup(to determine the type of request) is done and the request is processed with respect to its type.
393
394
394
395
```c
395
396
/*config_lookup called*/
@@ -433,7 +434,7 @@ if (lookup->type == REQ_FILE_SERVE) {
433
434
434
435
### main.c
435
436
436
-
Processes the command-line arguments to retrieve the configuration file path. The configuration is created which is followed by core creation.
437
+
Processes the command-line arguments to retrieve the configuration file path. The configuration object is created by invoking the method of `xps_config` module. Then `core_create` function is invoked which handles creation of listeners and attaching it with core in accordance with the `config` object. And then starts the core.
437
438
438
439
```c
439
440
intmain(int argc, char *argv[]) {
@@ -655,4 +656,4 @@ Now, navigate to `http://localhost:8001/` in your browser. You will notice that
655
656
656
657
## Conclusion
657
658
658
-
In this stage, we transitioned from a hardcoded server setup to a dynamic, configuration-driven architecture using JSON. By implementing the `config` module, eXpServer now supports multiple worker cores, reverse proxying, and URL redirects. While the server currently returns a 404 error when an index file is missing from a directory, we will resolve this in the next stage by implementing a dedicated directory module.
659
+
In this stage, we transitioned from a hardcoded server setup to a dynamic, configuration-driven architecture using a JSON config file. By implementing the `config` module, eXpServer now supports reverse proxying and URL redirects. The server currently returns a 404 error when an index file is missing from a directory, we will resolve this in the next stage by implementing a dedicated directory module.
Copy file name to clipboardExpand all lines: docs/roadmap/phase-2/stage-17.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## Recap
4
4
5
-
In the previous stages, we updated the server to handle HTTP messages. Stage 14 focused on implementing HTTP request parsing, while Stage 15 covered the construction of HTTP response messages. And in stage 16 we have implemented multiple cores, used a JSON file to set-up server configuration and implemented reverse proxy and URL redirecting in our webserver.
5
+
In the previous stages, we updated the server to handle HTTP messages. Stage 14 focused on implementing HTTP request parsing, while Stage 15 covered the construction of HTTP response messages. And in stage 16 we have implemented config module, used a JSON file to set-up server configuration and implemented reverse proxy and URL redirecting in our webserver.
0 commit comments