Package com.github.kevinsawicki.http

Examples of com.github.kevinsawicki.http.HttpRequest.header()


      vHttpRequest = new HttpRequest(pBankRequest.generateUri(), pMethod);
    }
    vHttpRequest.userAgent(USER_AGENT);
    modifyRequest(pBankRequest);
    for (Entry<String, String> header : pBankRequest.getHeaders().entrySet()) {
      vHttpRequest.header(header.getKey(), header.getValue());
    }
    return vHttpRequest;
  }

  @Override
View Full Code Here


        postData.put("context", new JSONObject());

        HttpRequest firstConnection = this.JsonRpc(getURLForMethod("session", "get_session_info"), "call", postData );

        // We retrieve and store werkzeug session cookie
        String cookies = firstConnection.header("Set-Cookie");
        _cookies = HttpCookie.parse(cookies);

        // We retrieve and store OpenERP session_id
        JSONObject body = new JSONObject(firstConnection.body());
        this._sessionId = (String) body.getJSONObject("result").get("session_id");
View Full Code Here

            StringBuffer cookieHeader = new StringBuffer();
            for( HttpCookie cookie : this._cookies) {
                cookieHeader.append(cookie.toString());
                cookieHeader.append(';');
            }
            request.header("Cookie", cookieHeader.toString());
        };

        JSONObject postData = new JSONObject();
        postData.put("json-rpc", "2.0");
        postData.put("method", method);
View Full Code Here

    @Test
    public void should_handle_good_origin_on_get() throws Exception {
        HttpRequest httpRequest = client().GET("/api/cors/1").header("Origin", "http://localhost:9000");
        assertHttpResponse(httpRequest, 200, "CORS1");
        assertThat(httpRequest.header("Access-Control-Allow-Origin")).isEqualTo("http://localhost:9000");
    }

    @Test
    public void should_handle_good_origin_on_post() throws Exception {
        HttpRequest httpRequest = client().POST("/api/cors/1").header("Origin", "http://localhost:9000").send("{}");
View Full Code Here

    @Test
    public void should_handle_good_origin_on_post() throws Exception {
        HttpRequest httpRequest = client().POST("/api/cors/1").header("Origin", "http://localhost:9000").send("{}");
        assertHttpResponse(httpRequest, 200, "CORS1");
        assertThat(httpRequest.header("Access-Control-Allow-Origin")).isEqualTo("http://localhost:9000");
    }

    @Test
    public void should_reject_invalid_origin_on_get() throws Exception {
        HttpRequest httpRequest = client().GET("/api/cors/1").header("Origin", "http://localhost:80");
View Full Code Here

    @Test
    public void should_handle_any_origin_on_get() throws Exception {
        HttpRequest httpRequest = client().GET("/api/cors/2").header("Origin", randomOrigin);
        assertHttpResponse(httpRequest, 200, "CORS2");
        assertThat(httpRequest.header("Access-Control-Allow-Origin")).isEqualTo(randomOrigin);
    }

    @Test
    public void should_handle_any_origin_on_post() throws Exception {
        HttpRequest httpRequest = client().POST("/api/cors/2").header("Origin", randomOrigin).send("{}");
View Full Code Here

    @Test
    public void should_handle_any_origin_on_post() throws Exception {
        HttpRequest httpRequest = client().POST("/api/cors/2").header("Origin", randomOrigin).send("{}");
        assertHttpResponse(httpRequest, 200, "CORS2");
        assertThat(httpRequest.header("Access-Control-Allow-Origin")).isEqualTo(randomOrigin);
    }

    @Test
    public void should_handle_any_origin_on_head() throws Exception {
        HttpRequest httpRequest = client().HEAD("/api/cors/2").header("Origin", randomOrigin);
View Full Code Here

    @Test
    public void should_handle_any_origin_on_head() throws Exception {
        HttpRequest httpRequest = client().HEAD("/api/cors/2").header("Origin", randomOrigin);
        assertHttpResponse(httpRequest, 204, "");
        assertThat(httpRequest.header("Access-Control-Allow-Origin")).isEqualTo(randomOrigin);
    }

    @Test
    public void should_reject_preflight_request_for_put_when_not_configured() throws Exception {
        HttpRequest httpRequest = client().OPTIONS("/api/cors/2")
View Full Code Here

        HttpRequest httpRequest = client().OPTIONS("/api/cors/3")
                .header("Origin", randomOrigin)
                .header("Access-Control-Request-Method", "PUT")
                ;
        assertHttpResponse(httpRequest, 200, "");
        assertThat(httpRequest.header("Access-Control-Allow-Origin")).isEqualTo(randomOrigin);
    }

    @Test
    public void should_reject_preflight_request_for_delete_when_not_configured() throws Exception {
        HttpRequest httpRequest = client().OPTIONS("/api/cors/3")
View Full Code Here

    @Test
    public void should_send_redirect() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET(
                "/api/core/webexception/redirect").followRedirects(false);
        assertThat(httpRequest.code()).isEqualTo(302);
        assertThat(httpRequest.header("Location")).isEqualTo("/api/core/hello?who=restx");
    }

    @Test
    public void should_follow_redirect() throws Exception {
        HttpRequest httpRequest = server.client().authenticatedAs("admin").GET(
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.