Why does Ktor server respond with 404 if a static directory's name starts with a dot? - server

I'm trying to serve static files with the following guide: https://ktor.io/docs/serving-static-content.html#serve-all-resources
I put ".well-known" directory inside "resources" directory and I have test1.html with the following path: resources/.well-known/test1.html.
Also, there is the following code:
embeddedServer(Natty, port = 8080) {
routing {
static("/") {
staticBasePackage = ".well-known"
resources(".")
}
}
}
When I start a server and make a request localhost:8080/test1.html I receive 404 Not found but if I rename ".well-known" to "well-known" (without a leading dot) I receive "200" and content of test1.html.
Why does Ktor server return 404 if a directory starts with a dot?
Ktor version is 2.0.2.

Related

Jetty: How to redirect base url programmatically?

I have to redirect myURL/ to myURL/webApp/
I found this piece of code
Server server = new Server();
RewriteHandler rewrite = new RewriteHandler();
RedirectPatternRule redirect = new RedirectPatternRule();
redirect.setPattern("/");
redirect.setReplacement("/myWebApp/"); // Getting compile error cannot resolve setReplacement method
rewrite.addRule(redirect);
Also, I didn't find setReplacement() in jetty documentaion.
https://archive.eclipse.org/jetty/8.0.0.M1/apidocs/org/eclipse/jetty/rewrite/handler/RedirectPatternRule.html
How can I achieve this redirect to base URL?

Add headers in response in user plugin

When retrieving a file from Artifactory, I would like to return its properties as HTTP headers.
Attempting to add headers to the response of a file download in the altResponse code block of the download plugin does not appear to work as I thought it would.
With the following user plugin loaded, I can see the code being executed from the logs, however, the header is not included in the response (using curl to download the file)
import org.artifactory.repo.RepoPath
import org.artifactory.request.Request
download {
altResponse { Request request, RepoPath responseRepoPath ->
headers = ["ExtraHeader":"SpecialHeader"]
log.warn "adding header: $headers"
}
}
logs:
2018-05-07 17:28:04,969 [http-nio-8088-exec-4] [WARN ] (properties :7) - adding header: [ExtraHeader:SpecialHeader]
documentation:
https://www.jfrog.com/confluence/display/RTF/User+Plugins#UserPlugins-Download
Running artifactory plugin development locally (currently loads version 5.11.0)
https://github.com/JFrogDev/artifactory-user-plugins-devenv
Am I misunderstanding how headers is supposed to be used?

Serving Static site with Caddy gives connection refused

I have caddy installed and running in my CentOS server,mainly I have it to proxy request to 2 Golang applications that I have running and it's working great! Now, I need to serve a static site, but i't returning connection refused
The structure of my directory is:
|--Caddyfile
|--mygolang1
|--mygolang2
|--FolderofMyStaticSite
|-----MySite
|-------Public
|----------index.html
And the caddyfile configuration is
:9000 {
root FolderofMyStaticSite/MySite/
log mySite
}
subdomain1.domain.com {
gzip
proxy / :7000 {
except /assets /robots.txt
}
}
subdomain2.domain.com {
proxy / :8000 {
max_fails 1
}
}
Then when I go to the browser and open xxx.xxx.xxx.xxx:9000 I get connection refused, why port 9000? it's because I have it only for testing not for production but I need a port to hear that site. What Am I missing? Thanks!

Unity 3D couldn't connect to host. localhost with ip

I am trying to HTTP POST to Laravel 5 using Unity.
The code is:
public void postToDB()
{
Debug.Log("in1");
WWWForm form = new WWWForm();
form.AddField("fb_id", "123123123");
WWW www = new WWW("http://localhost:777/new_fb_user",form);
StartCoroutine(WaitForRequest(www),form);
}
private IEnumerator WaitForRequest(WWW www)
{
Debug.Log("in2");
yield return www;
// check for errors
if (www.error == null)
{
Debug.Log("WWW Ok!: " + www.text);
}
else
{
Debug.Log("WWW Error: " + www.error);
}
}
When I try to use the postToDB method, I get this error:
WWW Error: couldn't connect to host UnityEngine.Debug:Log(Object)
<WaitForRequest>c__Iterator0:MoveNext() (at Assets/GameManger.cs:41)
I am using Wamp and I added a crossdomain.xml file.
If I change http://localhost:777/new_fb_user to any domain like Facebook or Google, it connects to that host. The POST command works: I tested it using Postman. So, I think the error is coming from Unity.
I finally fixed it , the problem that i was running the laravel project internally
using the normal
php artisan serve
which was as creating private internal server
i fix it using Xampp
-coping the laravel project to htdocs folder in Xampp directory
-running Xampp serve
it worked perfectly
Thanks for the help every one

Downloading file by WebClient Exception

I have a problem downloading particular file types by WebClient. So there are no problems with usual types - mp3, doc and others, but when I rename file extension to config it returns me:
InnerException = {System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
when I'm trying to access this file in browser (http://localhost:3182/Silverlight.config) - it's a usual xml file within - server returns me following error page:
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.config' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /Silverlight.config
So I suppose this hapens because of some server configuration, which blocks files of unknown type.
downloading code is simple:
WebClient webClient = new WebClient();
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
webClient.OpenReadAsync(new Uri("../Silverlight.config", UriKind.RelativeOrAbsolute));
completted eventhandler omitted for simplicity.
I'm not sure this is possible.
The .config extension is handled by the ASP.NET engine, for security reasons (sensitive data like connection strings need to be kept safe and hidden from unauthorized viewers).
This means that visitors cannot view your web.config file's content by simply entering "www.example.com/web.config" into their browser's adress bar.
EDIT : actually you can but I don't recommand it. If you really need to do it, you have to remove the mapping between the .config extension and ASP.NET ISAPI filter in IIS.