Skip to content

Commit f008b2c

Browse files
committed
Distinguish between html and json results during registration.
Json doesn't like getting a 203 - it prefers the regular response with a ReferrerUrl
1 parent 1d86882 commit f008b2c

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/ServiceStack.ServiceInterface/Auth/RegistrationService.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,19 @@ public object Post(Registration request)
156156
};
157157
}
158158

159-
if (string.IsNullOrEmpty(request.Continue))
160-
return response;
161-
162-
return new HttpResult(response) {
163-
Location = request.Continue
164-
};
159+
var isHtml = base.RequestContext.ResponseContentType.MatchesContentType(ContentType.Html);
160+
if (isHtml)
161+
{
162+
if (string.IsNullOrEmpty(request.Continue))
163+
return response;
164+
165+
return new HttpResult(response)
166+
{
167+
Location = request.Continue
168+
};
169+
}
170+
171+
return response;
165172
}
166173

167174
public UserAuth ToUserAuth(Registration request)

tests/ServiceStack.Common.Tests/OAuth/RegistrationServiceTests.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ public void Requires_unique_UserName_and_Email()
170170
}
171171

172172
[Test]
173-
public void Registration_with_Continue_returns_302_with_Location()
173+
public void Registration_with_Html_ContentType_And_Continue_returns_302_with_Location()
174174
{
175-
var service = GetRegistrationService();
175+
var service = GetRegistrationService(null, null, ContentType.Html);
176176

177177
var request = GetValidRegistration();
178178
request.Continue = "http://localhost/home";
@@ -187,7 +187,7 @@ public void Registration_with_Continue_returns_302_with_Location()
187187
[Test]
188188
public void Registration_with_EmptyString_Continue_returns_RegistrationResponse()
189189
{
190-
var service = GetRegistrationService();
190+
var service = GetRegistrationService(null, null, ContentType.Html);
191191

192192
var request = GetValidRegistration();
193193
request.Continue = string.Empty;
@@ -197,5 +197,20 @@ public void Registration_with_EmptyString_Continue_returns_RegistrationResponse(
197197
Assert.That(response as HttpResult, Is.Null);
198198
Assert.That(response as RegistrationResponse, Is.Not.Null);
199199
}
200+
201+
[Test]
202+
public void Registration_with_Json_ContentType_And_Continue_returns_RegistrationResponse_with_ReferrerUrl()
203+
{
204+
var service = GetRegistrationService(null, null, ContentType.Json);
205+
206+
var request = GetValidRegistration();
207+
request.Continue = "http://localhost/home";
208+
209+
var response = service.Post(request);
210+
211+
Assert.That(response as HttpResult, Is.Null);
212+
Assert.That(response as RegistrationResponse, Is.Not.Null);
213+
Assert.That(((RegistrationResponse)response).ReferrerUrl, Is.EqualTo("http://localhost/home"));
214+
}
200215
}
201216
}

0 commit comments

Comments
 (0)