WireMock. Ignore all request beside only one - wiremock

I start WireMock as standalone process:
java -jar wiremock-standalone-2.6.0.jar --port 8080 -v
OK.
When http request content suffix /api/profile/Favorite/ the WireMock must return stub response. On all other requests must by ignore by WireMock and must be forward to production server.
How I must config WireMock for this?

It sounds like you're looking for proxy behavior. For standalone WireMock you pass in --proxy-all="http://yourserver.com" as a parameter.
The section on Record and Playback in the docs has more examples.

Related

How to get the full URL from an Http4s Request

I'm trying to obtain the beginning of the URL that a client used to access a webserver in Http4s. I.e. given a Request[F] I want to obtain the string "http://localhost:8080" or "https://my-app.company.com" depending on where the server is deployed.
In a server implementation with Http4s, when receiving a Request via something like
HttpRoutes.of[IO] {
case req =>
println(req.uri)
???
}
I only ever seem to get a relative URI, e.g. / or /foo/bar - the scheme and authority fields on the Uri are both None.
It looks like I can pull the localhost:8080 part from the Host header on the request, but I have no solution for the scheme (http:// or https://).
How can I fill in the correct value for request.uri.scheme? And is there a more appropriate way to obtain the host?
FWIW I'm using http4s 0.22
You can't get it while using Blaze as an HTTP server. There are workarounds. You can catch bound of a server:
By port:
[io-compute-4] INFO org.http4s.blaze.channel.nio1.NIO1SocketServerGroup - Service bound to address /[0:0:0:0:0:0:0:0]:8080
By schema:
[io-compute-4] INFO org.http4s.blaze.server.BlazeServerBuilder - http4s v1.0.0-M33 on blaze v1.0.0-M33 started at http://[::]:8080/
Or you can map 8080 to HTTP and 8081 to HTTPS and make pattern matching on it.
A bad workaround would be to add it as an HTTP header and read it via Headers
It legacy practice but many legacy software companies are still using this approach.

Sending HTTP via proxy with haproxy

We have a company proxy (ip:port) and need to send HTTP POST with json payload to the URL like "http://server1.smthng.com/foo". Locally, name could not be resolved, but it is resolved at proxy. I dont understand how to configure haproxy to use proxy "ip:port" and send request without modifying the original URL.
I've tried curl to "http://server1.smthng.com/foo" after setting https_proxy variable from CLI (in linux) and it worked for me, so now I need to replicate same via haproxy.
From curl logs I could see that it first makes a CONNECT to proxy and once connection is there it POSTs the data.
I could be missing some knowledge here regarding tcp tunnels and the answer could be simple really. Anyway, need help.
The question is to be closed with no asnwer. The solution we took is via civetweb htt_proxy parameters.

Advanced Tweak on Undertow-handlers.conf for http https redirect

I use WildFly behind an AWS load balancer. I want the Undertow server in WildFly to redirect http traffic to https, and I can do this mostly successfully with the following line placed in undertow-handlers.conf:
equals('http', %{i,X-Forwarded-Proto}) -> redirect(https://app.server.com%U)
Thanks to these folks for getting me this far! Now here's my desired tweak. Sometimes I run my web application behind a testing load balancer using 'dev.server.com' and sometimes I run it behind a production load balancer using 'app.server.com.' Currently, I have to remember to manually edit undertow-handlers.conf any time I switch balancers. I'm hoping there is a way to change the hard-coded 'dev' and 'app' to something mechanical. Is there a way to tell Undertow to just use the domain name that was originally requested?
Thanks.
Thankfully the undertow configuration gives you access to the request headers via Exchange Attributes, which you're already using to access the X-Forwarded-Proto header. So the solution is to simply use the Host header from the request like so:
equals('http', %{i,X-Forwarded-Proto}) -> redirect(https://%{i,Host}%U)
If you want to keep it as part of the deployment try using the %h in the redirect expressions. For example:
equals('http', %{i,X-Forwarded-Proto}) -> redirect(https://%h%U)
Another option would be to configure the server to handle the redirect for you. The CLI commands would look something like the following assuming the default ports of 8080 for http and 8443 for https.
/subsystem=undertow/configuration=filter/rewrite=http-to-https:add(redirect=true, target="https://%h:8443%U")
/subsystem=undertow/server=default-server/host=default-host/filter-ref=http-to-https:add(predicate="equals(%p, 8080)")
You can see all the possible exchange attributes in the Undertow documentation.

Opening Foxx API to local network

I have setup serverend points they work for the web interface fine but the api endpoint for my for app do not even give a error and does not time out.
I have tried turn the app to production mode in the web interfaces no joy.
I look at the doc for server setup but can find any thing to help.
So I would think their is configure issue where should I look?
On localhost ever thing works.
On remote host where using 168.192.0.15:8530 only web interface works not my api form either curl or may app
Without further information I can only guess what the problem is, but I'll try:
The default --server.endpoint configuration value for an ArangoDB server is tcp://127.0.0.1:8529. That means you will be able to access it from the local machine but not from other hosts.
To make the server respond to HTTP requests originated from other hosts, you will need to use an endpoint that includes the server's IP address as used in your network, e.g. tcp://192.168.173.13:8529 and restart it with the adjusted configuration.
If that's not working either, can you trying calling the target URL from another server via curl and check the server's HTTP response code. This might reveal the source of the problem, too. Note that you should invoke curl with the option --dump - to see the HTTP response code. For example:
curl -X GET --dump - http://192.168.173.13:8529/your/app
If that is not producing any results (i.e. no response at all), you might have a firewall in between that blocks requests. Probably you need to allow access on the port ArangoDB uses (8529 by default and used in my example).
So I have learn the issue is the api endpoint url is not the same on localhost at their are from outside. Example:
curl -X GET --dump - http://localhost:8529/broad/broad/login
curl -X GET --dump - http://192.168.0.15:8530/_db/_system/broad/broad/login
https://docs.arangodb.com/cookbook/MakingFoxxAppAccessible.html
This lead me to my answer

Accessing couchdb futon thru https

I've got a problem accessing futon interface when it is proxied using nginx.
This config works fine when http protocol is used, but when I try to use
https, I constantly receive no_db_file errors (but operations succeed,
e.g. I can create databases, insert values, etc.)
location / {
proxy_pass http://127.0.0.1:5984;
}
What can I do to make it work correctly using https protocol?
I have used Apache proxying to proxy https to http to do https on CouchDB: http://wiki.apache.org/couchdb/Apache_As_a_Reverse_Proxy
I have found that a trailing slash on the URL affects whether or not https proxying works. Maybe it affects Nginx the same way?
That's not bad! At least you have a working link between nginx and CouchDB.
no_db_file is CouchDB's 404 response when a database (the first thing after the slash) is not there. Check the logs and see what path CouchDB actually received in the query. It may be one of the AJAX calls that Futon does; but whatever it is, the logs will say.