I am using Akka HTTP 10.0.15. Each response contains the header Server: akka-http/10.0.15. Is there any way to drop this header? I couldn't find anything in the list of directives.
In your application.conf, set akka.http.server.server-header to the empty string:
akka.http.server.server-header = ""
From the reference configuration:
akka.http {
server {
# The default value of the `Server` header to produce if no
# explicit `Server`-header was included in a response.
# If this value is the empty string and no header was included in
# the request, no `Server` header will be rendered at all.
server-header = akka-http/${akka.http.version}
...
}
...
}
Related
So I've managed to write a bunch of tests and in every feature file I set the same request headers.
For example:
Given url appUrl
And path '/path'
* header Accept = 'application/json'
I'd like to know if there's a way to set a header once so that it is set before each scenario is run. I've read the documentation and tried the callSingle method as follows in karate-config.js:
karate.callSingle('classpath:api/Utilities/Feature/header.feature');
header.feature looks like:
Feature: common routing that sets the headers for all features
Background:
* configure headers = { Accept : 'application/json' }
And example feature where I expect the headers to be preset:
Feature: Header Preset
Scenario: I expect the header to be set
Given url appUrl
And path '/path'
When method get
Then status 200
* print response
#I expect the response to be returned in JSON format
However I'm unable to get this working. I don't think I've understood how the callSingle method works. Some pointers would be helpful. Thanks.
Ignore callSingle for now and focus on configure headers.
I think you are missing one step - which is to ensure that configure headers has been "applied" before each Scenario. If you are 100% sure that this applies "globally", just do this in karate-config.js:
karate.configure('headers', { Accept: 'application/json' });
Else you use the Background (in each feature):
* configure headers = { Accept: 'application/json' }
Typically you have more steps that are common, so you have them in a "common" feature file and call that for every test. Refer: https://github.com/intuit/karate#shared-scope
I wrote a test that calls an api endpoint once and retrieves an etag in the response. After that I do a second call and I am setting the etag value to the if-none-match header. The test looks like the following:
Feature: Retrieve station properties
Background:
* url baseUrl
* def contentType = 'application/vnd.whatever'
* def accessToken = 'ey.foobar.123'
* configure headers = { Authorization: '#("Bearer " + accessToken)', Accept: '#(contentType)' }
Scenario: Fetch station properties once and expect a 304 on the sub-sequent request
Given path '/api/station-properties'
When method GET
Then status 200
And headers {ETag: '#notnull'}
And def etag = responseHeaders['ETag'][0]
Given path '/api/station-properties'
And header If-None-Match = etag
When method GET
Then status 304
This basically works but I was not happy with the configure headers line as I may add additional headers later on. Thus I thought about using a different method to set the headers:
Feature: Retrieve station properties
Background:
* url baseUrl
* def contentType = 'application/vnd.whatever'
* def accessToken = 'ey.foobar.123'
* header Authorization = 'Bearer ' + accessToken
* header Accept = contentType
Scenario: Fetch station properties once and expect a 304 on the sub-sequent request
Given path '/api/station-properties'
When method GET
Then status 200
And headers {ETag: '#notnull'}
And def etag = responseHeaders['ETag'][0]
Given path '/api/station-properties'
And header If-None-Match = etag
When method GET
Then status 304
In this case though, the headers (Authorization and Accept) are set on the first api call but on the second call they are not.
Why is this the case?
Yes, the rule is configure is to "persist" for multiple HTTP calls. So just make this change in the Background:
* configure headers = ({ Authorization: 'Bearer ' + accessToken, Accept: contentType })
Well, yes - do what you were doing earlier. Now it should work.
So I've managed to write a bunch of tests and in every feature file I set the same request headers.
For example:
Given url appUrl
And path '/path'
* header Accept = 'application/json'
I'd like to know if there's a way to set a header once so that it is set before each scenario is run. I've read the documentation and tried the callSingle method as follows in karate-config.js:
karate.callSingle('classpath:api/Utilities/Feature/header.feature');
header.feature looks like:
Feature: common routing that sets the headers for all features
Background:
* configure headers = { Accept : 'application/json' }
And example feature where I expect the headers to be preset:
Feature: Header Preset
Scenario: I expect the header to be set
Given url appUrl
And path '/path'
When method get
Then status 200
* print response
#I expect the response to be returned in JSON format
However I'm unable to get this working. I don't think I've understood how the callSingle method works. Some pointers would be helpful. Thanks.
Ignore callSingle for now and focus on configure headers.
I think you are missing one step - which is to ensure that configure headers has been "applied" before each Scenario. If you are 100% sure that this applies "globally", just do this in karate-config.js:
karate.configure('headers', { Accept: 'application/json' });
Else you use the Background (in each feature):
* configure headers = { Accept: 'application/json' }
Typically you have more steps that are common, so you have them in a "common" feature file and call that for every test. Refer: https://github.com/intuit/karate#shared-scope
I'm using WL.Server.invokeHttp(options) several times in my adapter. I need to have different values for a given cookie in different calls.
If I call
WL.Server.invokeHttp({cookies: {
mycookie: 'firstValue'
}
...
the back-end gets this header "cookie": "mycookie=firstValue", as expected.
If I later want to make another call with a different cookie value,
WL.Server.invokeHttp({cookies: {
mycookie: 'secondValue'
}
...
the back-end gets this header "cookie": "mycookie=firtsValue; mycookie=secondValue".
Is there some way that will let me forget a previous value of the cookie?
Update 2015/02/27
Using the headers option instead of the cookies option, as suggested by #YoelNunez, does not solve it.
My first request gets a "set-cookie": "name=value1; Path=/" response header
My second request sets headers: {cookie: 'name=value2'}
The second requests gets to the server with the following header "cookie": "name=value2, name=value1"
Change you invokeHttp to the following
WL.Server.invokeHttp({
headers: {
cookie: "mycookie="+myCookieValue
}
...
});
Where myCookieValue is your variable
I have to create the go remote-import server for my project using by apache and I try to create perl module for handler the go get request from user.
The perl module (RemoteImport.pm) was show in below:
sub handler{
my $r = shift;
# check if request is from "go"
return Apache2::Const::DECLINED if ($r->args() !~ /go\-get=1$/);
// Code for provide necessary http body data for go get request and return OK.
}
Apache config:
PerlModule Gerrit::Go::RemoteImport
<Location />
SetHandler perl-script
PerlResponseHandler Gerrit::Go::RemoteImport
</Location>
The go get request can be use normally but I found problem in another http request that have path begin with "/", the Apache does not continue to serve the request as it normally and give not-found page.
Please help me to solve this problem.
I get solution from my team as bellow:
sub go_remote_import_response {
my $r = shift;
# Code for provide necessary http body data for go get request and return OK.
}
sub handler {
my $r = shift;
# check if request is from "go"
return Apache2::Const::OK if ($r->args() !~ /go\-get=1$/);
# change the response handler to our handler if the request are from "go"
$r->handler('perl-script');
$r->set_handlers(PerlResponseHandler => \&go_remote_import_response);
return Apache2::Const::OK;
}