Respond with application/json for the register submitToken.
This commit is contained in:
@@ -33,6 +33,7 @@ import io.kamax.mxisd.util.RestClientUtils;
|
|||||||
import io.undertow.server.HttpHandler;
|
import io.undertow.server.HttpHandler;
|
||||||
import io.undertow.server.HttpServerExchange;
|
import io.undertow.server.HttpServerExchange;
|
||||||
import io.undertow.server.handlers.form.FormData;
|
import io.undertow.server.handlers.form.FormData;
|
||||||
|
import io.undertow.util.Headers;
|
||||||
import io.undertow.util.HttpString;
|
import io.undertow.util.HttpString;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -203,26 +204,34 @@ public abstract class BasicHttpHandler implements HttpHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void proxyPost(HttpServerExchange exchange, JsonObject body, CloseableHttpClient client, ClientDnsOverwrite dns) {
|
protected void proxyPost(HttpServerExchange exchange, JsonObject body, CloseableHttpClient client, ClientDnsOverwrite dns) {
|
||||||
|
proxyPost(exchange, body, client, dns, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void proxyPost(HttpServerExchange exchange, JsonObject body, CloseableHttpClient client, ClientDnsOverwrite dns,
|
||||||
|
boolean defaultJsonResponse) {
|
||||||
String target = dns.transform(URI.create(exchange.getRequestURL())).toString();
|
String target = dns.transform(URI.create(exchange.getRequestURL())).toString();
|
||||||
log.info("Requesting remote: {}", target);
|
log.info("Requesting remote: {}", target);
|
||||||
HttpPost req = RestClientUtils.post(target, GsonUtil.get(), body);
|
HttpPost req = RestClientUtils.post(target, GsonUtil.get(), body);
|
||||||
|
|
||||||
exchange.getRequestHeaders().forEach(header -> {
|
exchange.getRequestHeaders().forEach(header -> header.forEach(v -> {
|
||||||
header.forEach(v -> {
|
String name = header.getHeaderName().toString();
|
||||||
String name = header.getHeaderName().toString();
|
if (!StringUtils.startsWithIgnoreCase(name, "content-")) {
|
||||||
if (!StringUtils.startsWithIgnoreCase(name, "content-")) {
|
req.addHeader(name, v);
|
||||||
req.addHeader(name, v);
|
}
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
boolean missingJsonResponse = true;
|
||||||
try (CloseableHttpResponse res = client.execute(req)) {
|
try (CloseableHttpResponse res = client.execute(req)) {
|
||||||
exchange.setStatusCode(res.getStatusLine().getStatusCode());
|
exchange.setStatusCode(res.getStatusLine().getStatusCode());
|
||||||
for (Header h : res.getAllHeaders()) {
|
for (Header h : res.getAllHeaders()) {
|
||||||
for (HeaderElement el : h.getElements()) {
|
for (HeaderElement el : h.getElements()) {
|
||||||
|
missingJsonResponse = !Headers.CONTENT_TYPE_STRING.equalsIgnoreCase(h.getName());
|
||||||
exchange.getResponseHeaders().add(HttpString.tryFromString(h.getName()), el.getValue());
|
exchange.getResponseHeaders().add(HttpString.tryFromString(h.getName()), el.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (defaultJsonResponse && missingJsonResponse) {
|
||||||
|
exchange.getRequestHeaders().add(Headers.CONTENT_TYPE, "application/json");
|
||||||
|
}
|
||||||
res.getEntity().writeTo(exchange.getOutputStream());
|
res.getEntity().writeTo(exchange.getOutputStream());
|
||||||
exchange.endExchange();
|
exchange.endExchange();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@@ -71,7 +71,7 @@ public class Register3pidRequestTokenHandler extends BasicHttpHandler {
|
|||||||
throw new NotAllowedException("Your " + medium + " address cannot be used for registration");
|
throw new NotAllowedException("Your " + medium + " address cannot be used for registration");
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyPost(exchange, body, client, dns);
|
proxyPost(exchange, body, client, dns, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user