aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/java/fi/iki/elonen/HttpSessionHeadersTest.java
blob: 75a0a49143b783b5a631d652bc07ac74f2c789c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package fi.iki.elonen;

import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.net.InetAddress;

import static org.junit.Assert.assertEquals;

public class HttpSessionHeadersTest extends HttpServerTest {
    private static final String DUMMY_REQUEST_CONTENT = "dummy request content";
    private static final TestTempFileManager TEST_TEMP_FILE_MANAGER = new TestTempFileManager();

    @Override
    public void setUp() {
        super.setUp();
    }

    @Test
    public void testHeadersRemoteIp() throws Exception {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(DUMMY_REQUEST_CONTENT.getBytes());
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        String[] ipAddresses = { "127.0.0.1", "192.168.1.1", "192.30.252.129" };
        for(String ipAddress : ipAddresses) {
            InetAddress inetAddress = InetAddress.getByName(ipAddress);
            NanoHTTPD.HTTPSession session = testServer.createSession(TEST_TEMP_FILE_MANAGER, inputStream, outputStream, inetAddress);
            assertEquals(ipAddress, session.getHeaders().get("remote-addr"));
            assertEquals(ipAddress, session.getHeaders().get("http-client-ip"));
        }
    }

}