MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / HTTPSession

Class HTTPSession

src/main/java/fielded/webserver/NanoHTTPD.java:631–1125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

629 }
630
631 protected class HTTPSession implements IHTTPSession {
632 public static final int BUFSIZE = 8192;
633 private final OutputStream outputStream;
634 private PushbackInputStream inputStream;
635 private int splitbyte;
636 private int rlen;
637 private String uri;
638 private Method method;
639 private Map<String, String> parms;
640 private Map<String, String> headers;
641 private CookieHandler cookies;
642 private String queryParameterString;
643
644 public HTTPSession(InputStream inputStream, OutputStream outputStream) {
645 this.inputStream = new PushbackInputStream(inputStream, BUFSIZE);
646 this.outputStream = outputStream;
647 }
648
649 public HTTPSession(InputStream inputStream, OutputStream outputStream, InetAddress inetAddress) {
650 this.inputStream = new PushbackInputStream(inputStream, BUFSIZE);
651 this.outputStream = outputStream;
652 String remoteIp = inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress() ? "127.0.0.1" : inetAddress.getHostAddress().toString();
653 headers = new HashMap<String, String>();
654
655 headers.put("remote-addr", remoteIp);
656 headers.put("http-client-ip", remoteIp);
657 }
658
659 @Override
660 public void execute() throws IOException {
661 try {
662 // Read the first 8192 bytes.
663 // The full header should fit in here.
664 // Apache's default header limit is 8KB.
665 // Do NOT assume that a single read will get the entire header at once!
666 byte[] buf = new byte[BUFSIZE];
667 splitbyte = 0;
668 rlen = 0;
669 {
670 int read = -1;
671 try {
672 read = inputStream.read(buf, 0, BUFSIZE);
673 } catch (Exception e) {
674 safeClose(inputStream);
675 safeClose(outputStream);
676 throw new SocketException("NanoHttpd Shutdown");
677 }
678 if (read == -1) {
679 // socket was been closed
680 safeClose(inputStream);
681 safeClose(outputStream);
682 throw new SocketException("NanoHttpd Shutdown");
683 }
684 while (read > 0) {
685 rlen += read;
686 splitbyte = findHeaderEnd(buf, rlen);
687 if (splitbyte > 0)
688 break;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected