Akka http redirect but change method from POST to GET - akka-http

I have endpoint using POST method ( registering token for example ), after job done I want to redirect client to "/" url, but using GET not POST.
How to achieve this ?
For now I have:
redirect("/", StatusCodes.PermanentRedirect)

What you want in this case is not a redirect with status code PermanentRedirect, but rather SeeOther (303). So you would have instead: redirect("/", StatusCodes.SeeOther)
You can check in RFC 7231, section 6.4.4: 303 See Other that this guarantees the behavior you describe.

Related

Rest assured is giving 502 in return

I have simple get API
https://abc.xyz.co/index.php?route=efg/api/jkl&key=8454jdgdkjf948754&source=android&user_id=44
when i hit in browser I receive 200 OK but when i send request using rest assured it gives 502 in return.
Below is the code I am using
RestAssured.baseURI = "https://abc.xyz.co/";
RequestSpecification request = RestAssured.given();
Response response = request.queryParam("route", "efg/api/jkl").
queryParam("key","8454jdgdkjf948754").
queryParam("source","android").
queryParam("user_id","44").get("/index.php");
System.out.println(response.getStatusCode());
Someone please look into this
Note: URL shared is dummy URL but format is same as per my project
I think the problem is in base url and endpoint url:
"https://abc.xyz.co/"
"/index.php"
which gives together "https://abc.xyz.co//index.php", so one slash character "/" is redundant. Try to remove it either for base url or endpoint url and it should work.

OAuth 2(Pinterest) - Query Param in callback URL?

My OAuth 2 callback URL is:
https://www.my-site.com?fixed=value
Where I have a query param that's fixed and does not change(and it unfortunately needs to be there for unrelated reasons). When Pinterest does the redirect call after user logs in, they add the ? again. So something like:
https://www.my-site.com?fixed=value?code=122343
Where my API is interpreting the value of the fixed param as value?code=122343 and breaks down. Is there any around this ?
You have to change callback url from https://www.my-site.com?fixed=value to https://www.my-site.com/fixed/value or you can try to add a custom parser to parse this url in your API.
In my case I was having a query param option called 'state'.I put my constant data in it and after authorize, I got my constant data in 'state' query param again when I redirected to my app.

In karate mocking (karate-netty), how can we override request header value?

Objective:
We want few API calls should go to mock-server(https://192.x.x.x:8001) and others should go to an actual downstream application server(https://dev.api.acme.com).
Setup :
On local, mock server is up with standalone jar on port 8001. e.g https://192.x.x.x:8001
In application config file (config.property)downstream system(which need to mock) defined with mockserver IP i.e https://192.x.x.x:8001
Testing scenario and problem:
1.
Scenario: pathMatches('/profile/v1/users/{id}/user')
* karate.proceed('https://dev.api.acme.com')
* def response = read ('findScope.json')
* def responseStatus = 200ˀˀ
* print 'created response is: ' + response
Now, when we hit API request via postman or feature file then it does karate.proceed properly to https://dev.api.acme.com/profile/v1/users/123/user instead of 192.x.x.x. However, in this request, host is referring to https://192.x.x.x:8001 instead of https://dev.api.acme.com which create a problem for us.
How can we override request header in this case? I did try with karate.set and also with header host=https://192.x.x.x:8001 but no luck.
Thanks!
Please see if the 1.0 version works: https://github.com/intuit/karate/wiki/1.0-upgrade-guide
Unfortunately https proxying may not work as mentioned. If you are depending on this, we may need your help (code contribution) to get this working
If the Host header is still not mutable, that also can be considered a feature request, and here also I'd request you to consider contributing code

in Karate DSL, is there a way to have redirects perform a POST request instead of a GET request? [duplicate]

This question already has an answer here:
Post method gets converted to GET after redirection
(1 answer)
Closed 2 years ago.
I have the following Karate script that by default has redirects turned on.
Scenario: First Test
Given path 'somePath'
And request ''
And header Content-Type = 'text/html'
And param _csrf = csrf
And param username = 'username'
And param password = 'password'
When method post
Then status 200
The issue is after getting a 302 from the API, the next request automatically submits a GET request. I would like it to submit a POST request instead.
in cURL, there is an existing parameter that allows users to do that. see below.
--post302 Do not switch to GET after following a 302
is there anyway to do that in Karate DSL?
Yes please read the docs for configure folowRedirects. There is also an example on how to read the Location response header to manually make the request you want.
Scenario: get redirects can be disabled
* configure followRedirects = false
Given path 'redirect'
When method get
Then status 302
And match header Location == demoBaseUrl + '/search'
* def location = responseHeaders['Location'][0]
Given url location

Difference between UseStatusCodePagesWithRedirects and UseStatusCodePagesWithReExecute - Status Code Pages in Asp.net core

I am using UseStatusCodePages Middleware to show status code pages on my application but it shows plain text on UI without any other information,
I want to show UI with Status Code Information along with some other helpful information like Customer Support Number with more user-friendly page.
I found out we can use two extension methods to do that which is UseStatusCodePagesWithRedirects and UseStatusCodePagesWithReExecute. Only Difference I found out from Microsoft Docs is,
UseStatusCodePagesWithRedirects : Send 302 to Client.
UseStatusCodePagesWithReExecute : Send Original Status Code and Executes handler for redirect URL.
Is that the only difference?
I think that the main difference is that UseStatusCodePagesWithRedirects is redirecting you to error controller action method while UseStatusCodePagesWithReExecute is just rendering page with out redirecting
Example
Controller actions
[Route("error/404")]
public IActionResult Error404(int code)
{
return View("Error404");
}
[Route("error/{code}")]
public IActionResult Error(int code)
{
return StatusCode(code);
}
Startup Cinfigue
app.UseStatusCodePagesWithRedirects("/error/{0}");
or
app.UseStatusCodePagesWithReExecute("/error/{0}");
Case 1 (404 Error)
Url : https://localhost:5001/notexits_page
1) UseStatusCodePagesWithRedirects
Result:
Url is: https://localhost:5001/error/404
We see Error404 page
2) UseStatusCodePagesWithReExecute
Result:
Url is: https://localhost:5001/notexits_page
We see Error404 page
Case2 (401 Error)
Url : https://localhost:5001/admin/users
1) UseStatusCodePagesWithRedirects
Result:
Url is: https://localhost:5001/error/401
We stack in infinity loop
1) UseStatusCodePagesWithRedirects
Result:
Url is: https://localhost:5001/admin/users
We see default browser error page for 401 error
When Using app.UseStatusCodePagesWithRedirects("/Error/{0}") and invalid request(lets say "/abc/xyz") is raised then;
Status Code 404 is issued, app.UseStatusCodePagesWithRedirects("/Error/{0}") intercepts the request and 302 status code is issued(which means URI of the requested resource has been changed temporarily)
As 302 is issued another get request is issued which results in change of the url from
"/abc/xyz" to "/Error/404".
As the request is redirected to the specific error controller the status code for the request is 200 ok in the browser developer tool.
But When Using app.UseStatusCodePagesWithReExecute("/Error/{0}") and invalid request(lets say "/abc/xyz") is raised then;
app.UseStatusCodePagesWithReExecute("/Error/{0}") middleware intercepts the 404 status code and re-executes the pipeline pointing it to the URL
As the middleware is re executing the pipeline the original URL "/abc/xyz" in the address bar is preserved. It does not change from "/abc/xyz" to "/Error/{0}".
Also the original status Code(404 in this case) is preserved in the developer tool.