提交 731dcf41 编写于 作者: K kohsuke

Remote API served incorrect absolute URLs when Hudson is run behind a reverse proxy.

    (<a href="http://www.netbeans.org/issues/show_bug.cgi?id=165067">report</a>)


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@18091 71c3de6d-444a-0410-be80-ed276b4c234a
上级 2765070f
......@@ -178,7 +178,7 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
StaplerRequest request = Stapler.getCurrentRequest();
if(request==null)
throw new IllegalStateException("Not processing a HTTP request");
return Util.encode(request.getRootPath()+'/'+getUrl());
return Util.encode(Hudson.getInstance().getRootUrl()+getUrl());
}
/**
......
......@@ -1476,14 +1476,10 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
* such as "http://localhost/hudson/".
*
* <p>
* Also note that when serving user requests from HTTP, you should always use
* {@link HttpServletRequest} to determine the full URL, instead of using this
* (this is because one host may have multiple names, and {@link HttpServletRequest}
* accurately represents what the current user used.)
*
* <p>
* This information is rather only meant to be useful for sending out messages
* via non-HTTP channels, like SMTP or IRC, with a link back to Hudson website.
* This method first tries to use the manually configured value, then
* fall back to {@link StaplerRequest#getRootPath()}.
* It is done in this order so that it can work correctly even in the face
* of a reverse proxy.
*
* @return
* This method returns null if this parameter is not configured by the user.
......
......@@ -166,7 +166,7 @@ public class User extends AbstractModelObject implements AccessControlled, Savea
*/
@Exported(visibility=999)
public String getAbsoluteUrl() {
return Stapler.getCurrentRequest().getRootPath()+'/'+getUrl();
return Hudson.getInstance().getRootUrl()+getUrl();
}
/**
......
......@@ -220,7 +220,7 @@ public abstract class View extends AbstractModelObject implements AccessControll
*/
@Exported(visibility=2,name="url")
public String getAbsoluteUrl() {
return Stapler.getCurrentRequest().getRootPath()+'/'+getUrl();
return Hudson.getInstance().getRootUrl()+getUrl();
}
public Api getApi() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册