Browse Source
A getCookies method is now available on ServerHttpRequest with one ServletServerCookie implementation that wraps a Servlet cookie. The SockJS service makes use of this to check for an existing session cookie in the request.pull/325/merge
26 changed files with 253 additions and 348 deletions
@ -1,59 +0,0 @@
@@ -1,59 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2013 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.http; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
|
||||
public class Cookies { |
||||
|
||||
private final List<Cookie> cookies; |
||||
|
||||
|
||||
public Cookies() { |
||||
this.cookies = new ArrayList<Cookie>(); |
||||
} |
||||
|
||||
private Cookies(Cookies cookies) { |
||||
this.cookies = Collections.unmodifiableList(cookies.getCookies()); |
||||
} |
||||
|
||||
public static Cookies readOnlyCookies(Cookies cookies) { |
||||
return new Cookies(cookies); |
||||
} |
||||
|
||||
public List<Cookie> getCookies() { |
||||
return this.cookies; |
||||
} |
||||
|
||||
public Cookie getCookie(String name) { |
||||
for (Cookie c : this.cookies) { |
||||
if (c.getName().equals(name)) { |
||||
return c; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public Cookie addCookie(String name, String value) { |
||||
DefaultCookie cookie = new DefaultCookie(name, value); |
||||
this.cookies.add(cookie); |
||||
return cookie; |
||||
} |
||||
|
||||
} |
||||
@ -1,42 +0,0 @@
@@ -1,42 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2013 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.http; |
||||
|
||||
import org.springframework.util.Assert; |
||||
|
||||
public class DefaultCookie implements Cookie { |
||||
|
||||
private final String name; |
||||
|
||||
private final String value; |
||||
|
||||
DefaultCookie(String name, String value) { |
||||
Assert.hasText(name, "cookie name must not be empty"); |
||||
this.name = name; |
||||
this.value = value; |
||||
} |
||||
|
||||
@Override |
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
@Override |
||||
public String getValue() { |
||||
return value; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.http.server; |
||||
|
||||
import org.springframework.http.Cookie; |
||||
|
||||
|
||||
/** |
||||
* A {@link Cookie} that wraps a {@link javax.servlet.http.Cookie}. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @since 4.0 |
||||
*/ |
||||
public class ServletServerCookie implements Cookie { |
||||
|
||||
private final javax.servlet.http.Cookie servletCookie; |
||||
|
||||
|
||||
public ServletServerCookie(javax.servlet.http.Cookie servletCookie) { |
||||
this.servletCookie = servletCookie; |
||||
} |
||||
|
||||
@Override |
||||
public String getName() { |
||||
return this.servletCookie.getName(); |
||||
} |
||||
|
||||
@Override |
||||
public String getValue() { |
||||
return this.servletCookie.getValue(); |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return this.servletCookie.getPath(); |
||||
} |
||||
|
||||
@Override |
||||
public String getComment() { |
||||
return this.servletCookie.getComment(); |
||||
} |
||||
|
||||
@Override |
||||
public String getDomain() { |
||||
return this.servletCookie.getDomain(); |
||||
} |
||||
|
||||
@Override |
||||
public int getMaxAge() { |
||||
return this.servletCookie.getMaxAge(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isSecure() { |
||||
return this.servletCookie.getSecure(); |
||||
} |
||||
|
||||
@Override |
||||
public int getVersion() { |
||||
return this.servletCookie.getVersion(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "ServletServerCookie [servletCookie=" + this.servletCookie + "]"; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue