question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RequestHook]: add methods for manipulation with response headers

See original GitHub issue

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
miherlosevcommented, Oct 12, 2018

Yes, it’s more appropriate to mark the onConfigureResponse event as public and remove the default implementation from the RequestHook base class. We will do it only before the testcafe@1.0.0 was released, because it’s a breaking change. Now, let’s keep this method as is. So, the use of the setHeader and removeHeader methods will look like this:

class CustomRequestHook extends RequestHook {
    _onConfigureResponse (event) {
      super._onConfigureResponse(event);
 
     event.setHeader('x-frame-options', 'allow-from https://example.com/');
     event.removeHeader('x-header-name');
    }
}
1reaction
miherlosevcommented, Oct 11, 2018

Having discussed this with the team, we can suggest the following API:

  • removeHeader(name)
  • setHeader(name, value)

These methods will be defined as methods of the ConfigureResponseEvent class.

The feature implementation can be divided into 2 parts:

  • split the header-transforms.js file into two parts:

    1. header-transforms.js - contains only transformations for request and response headers
    2. header-transform-api.js - contains the forRequest, forResponse and transformHeadersCaseToRaw methods
  • change response headers transformation order.

    1. apply all header changes from request hooks
    2. apply header transformation
    3. write updated headers to the response.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Add response headers via RequestHook - Stack Overflow
Currently, the only way to add the headers to the response is to use the private _onConfigureResponse method of the RequestHook class:
Read more >
Request hook's onResponse method not being called #4070
But I want to manipulate the response headers of a request. So I set up a request hook: const { RequestHook } =...
Read more >
RequestHook Class | Test API | API | Docs - TestCafe
To change response headers, use the event.setHeader and event.removeHeader methods in the __onConfigureResponse call. Important. The RequestHook.
Read more >
Back to Basics: Custom HTTP Response Header Manipulation ...
NET Core doesn't have an obvious, built-in way to add headers to every request. In this back to basics post I describe what...
Read more >
End-to-End Testing with TestCafe Book Excerpt: Intercepting ...
The fixture and test functions have a method called requestHooks where you can attach either an instance of RequestLogger or RequestMock .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found