Repository: nervosnetwork/ckb (language: rust)

Issue:
Error from RPC on GET request: "Missing request extension: Extension of type `jsonrpc_utils::stream::StreamServerConfig` was not found."
## Bug Report

The following error is received on the RPC when sending a GET request from a browser:

```txt
Missing request extension: Extension of type `jsonrpc_utils::stream::StreamServerConfig` was not found. Perhaps you forgot to add it? See `axum::Extension`.
```
### Expected Behavior

The RPC should return a more appropriate error.

### Environment

- **CKB version**: v0.113.0
- **Operating system**: Ubuntu 20.04
- **Arch**: x64 Linux 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
- **Installation**: GitHub Release



Discussion / hints:
Send `GET` request to `v0.110.0` will get this:
```bash
$ curl -s -X GET http://127.0.0.1:8114 -H 'Content-Type: application/json' -d '{ "id": 42, "jsonrpc": "2.0", "method": "sync_state", "params": [ ] }'
Used HTTP Method is not allowed. POST or OPTIONS is required
```

Send `Get` request to v0.113.0` will get this:
```bash
$ curl -s -X GET http://127.0.0.1:8114 -H 'Content-Type: application/json' -d '{ "id": 42, "jsonrpc": "2.0", "method": "sync_state", "params": [ ] }'
Missing request extension: Extension of type `jsonrpc_utils::stream::StreamServerConfig` was not found. Perhaps you forgot to add it? See `axum::Extension`.%
```

Fix patch:
diff --git a/rpc/src/server.rs b/rpc/src/server.rs
index 6d943211d5..07a4c20eed 100644
--- a/rpc/src/server.rs
+++ b/rpc/src/server.rs
@@ -1,11 +1,13 @@
 use crate::IoHandler;
-use axum::routing::post;
+use axum::response::IntoResponse;
+use axum::routing::{get, post};
 use axum::{Extension, Router};
 use ckb_app_config::RpcConfig;
 use ckb_async_runtime::Handle;
 use ckb_error::AnyError;
 use ckb_logger::info;
 
+use axum::http::StatusCode;
 use ckb_stop_handler::{new_tokio_exit_rx, CancellationToken};
 use futures_util::{SinkExt, TryStreamExt};
 use jsonrpc_core::MetaIoHandler;
@@ -90,14 +92,22 @@ impl RpcServer {
             .with_pipeline_size(4);
 
         // HTTP and WS server.
-        let method_router =
-            post(handle_jsonrpc::<Option<Session>>).get(handle_jsonrpc_ws::<Option<Session>>);
+        let post_router = post(handle_jsonrpc::<Option<Session>>);
+        let get_router = if enable_websocket {
+            get(handle_jsonrpc_ws::<Option<Session>>)
+        } else {
+            get(get_error_handler)
+        };
+        let method_router = post_router.merge(get_router);
+
         let mut app = Router::new()
             .route("/", method_router.clone())
             .route("/*path", method_router)
+            .route("/ping", get(ping_handler))
             .layer(Extension(Arc::clone(rpc)))
             .layer(CorsLayer::permissive())
-            .layer(TimeoutLayer::new(Duration::from_secs(30)));
+            .layer(TimeoutLayer::new(Duration::from_secs(30)))
+            .layer(Extension(stream_config.clone()));
 
         if enable_websocket {
             let ws_config: StreamServerConfig =
@@ -179,3 +189,16 @@ impl RpcServer {
         Ok(tcp_address)
     }
 }
+
+/// used for compatible with old health endpoint
+async fn ping_handler() -> impl IntoResponse {
+    "pong"
+}
+
+/// used for compatible with old PRC error responce for GET
+async fn get_error_handler() -> impl IntoResponse {
+    (
+        StatusCode::METHOD_NOT_ALLOWED,
+        "Used HTTP Method is not allowed. POST or OPTIONS is required",
+    )
+}


Test patch: