Created
June 20, 2015 18:31
-
-
Save swankjesse/e46017775bb30f7e52c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.squareup.okhttp; | |
import com.squareup.okhttp.mockwebserver.Dispatcher; | |
import com.squareup.okhttp.mockwebserver.MockResponse; | |
import com.squareup.okhttp.mockwebserver.MockWebServer; | |
import com.squareup.okhttp.mockwebserver.RecordedRequest; | |
import java.io.IOException; | |
import javax.xml.stream.XMLOutputFactory; | |
import javax.xml.stream.XMLStreamException; | |
import javax.xml.stream.XMLStreamWriter; | |
import okio.Buffer; | |
public class FormServer { | |
public static void main(String[] args) throws IOException { | |
MockWebServer server = new MockWebServer(); | |
server.setDispatcher(new Dispatcher() { | |
@Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException { | |
if (request.getBody() != null) { | |
System.out.println(request.getBody().readUtf8()); | |
} | |
Buffer buffer = new Buffer(); | |
buffer.writeUtf8("" | |
+ "<html>" | |
+ "<form accept-charset='UTF-8' method='POST' action='/'>"); | |
try { | |
XMLStreamWriter writer = XMLOutputFactory.newFactory() | |
.createXMLStreamWriter(buffer.outputStream(), "UTF-8"); | |
for (int codePoint = 0; codePoint < 10000; codePoint++) { | |
String codePointString = new String(new int[] { codePoint }, 0, 1); | |
writer.writeStartElement("input"); | |
writer.writeAttribute("type", "text"); | |
writer.writeAttribute("name", "utf8_" + codePoint); | |
writer.writeAttribute("value", codePointString); | |
writer.writeEndElement(); | |
} | |
writer.close(); | |
} catch (XMLStreamException e) { | |
} | |
buffer.writeUtf8("" | |
+ "<input type='submit'>" | |
+ "</form>" | |
+ "</html>"); | |
return new MockResponse() | |
.addHeader("Content-Type", "text/html; charset=UTF-8") | |
.setBody(buffer.readUtf8()); | |
} | |
}); | |
server.start(); | |
System.out.println(server.getUrl("/")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment