Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getHttpRpcClient onRequest change request , should send request #2741

Closed
1 task done
841660202 opened this issue Sep 19, 2024 · 4 comments
Closed
1 task done

getHttpRpcClient onRequest change request , should send request #2741

841660202 opened this issue Sep 19, 2024 · 4 comments
Labels
needs reproduction Misc: Needs Reproduction

Comments

@841660202
Copy link

Check existing issues

Viem Version

latest

Current Behavior

viem/src/utils/rpc/http.ts

Lines 103 to 105 in 15c71b6

const request = new Request(url, init)
if (onRequest) await onRequest(request)
const response = await fetch(url, init)

onRequest change request , should send request

Expected Behavior

If onRequest change request, should send request

Steps To Reproduce

createPublicClient({
      chain: chain,
      transport:  http(chain?.rpcUrls.default.http[0], {
        onFetchRequest: async (request: Request) => {
          // const bodyText = await request.clone().text()
          // const body = JSON.parse(bodyText)
          // const method = Array.isArray(body) ? body[0].method : body.method
          // request.headers.set('X-Proxy-Jsonrpc-Method', method)
          // console.log('request', request)
        },
     })
  })

Link to Minimal Reproducible Example

No response

Anything else?

viem/src/utils/rpc/http.ts

Lines 103 to 105 in 15c71b6

const request = new Request(url, init)
if (onRequest) await onRequest(request)
const response = await fetch(url, init)

onRequest change request , should send request

const response = await fetch(url, init) send url & init, here should request

This is MDN https://developer.mozilla.org/zh-CN/docs/Web/API/Request

fetch(request)
  .then((response) => {
    if (response.status === 200) {
      return response.json();
    } else {
      throw new Error("Something went wrong on API server!");
    }
  })
  .then((response) => {
    console.debug(response);
    // …
  })
  .catch((error) => {
    console.error(error);
  });
@841660202 841660202 reopened this Sep 19, 2024
@jxom
Copy link
Member

jxom commented Sep 19, 2024

What is the issue? Not too sure what you mean – please properly fill out a bug report including a minimal reproducible example.

@jxom jxom added the needs reproduction Misc: Needs Reproduction label Sep 19, 2024
Copy link
Contributor

Hello @841660202.

Please provide a minimal reproduction using StackBlitz, TypeScript Playground (for type issues), or a separate minimal GitHub repository.

Minimal reproductions are required as they save us a lot of time reproducing your config/environment and issue, and allow us to help you faster.

Once a minimal reproduction is added, a team member will confirm it works, then re-open the issue.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2024
@jxom
Copy link
Member

jxom commented Sep 19, 2024

possibly dupe of #2630

Copy link
Contributor

github-actions bot commented Oct 5, 2024

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Viem version. If you have any questions or comments you can create a new discussion thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs reproduction Misc: Needs Reproduction
Projects
None yet
Development

No branches or pull requests

2 participants