Package org.apache.http

Examples of org.apache.http.HeaderElement


        Header header = entity.getContentType();
        HeaderElement[] elems = header.getElements();
        assertNotNull(elems);
        assertEquals(1, elems.length);

        HeaderElement elem = elems[0];
        assertEquals("multipart/form-data", elem.getName());
        NameValuePair p1 = elem.getParameterByName("boundary");
        assertNotNull(p1);

        String boundary = p1.getValue();
        assertNotNull(boundary);

        assertTrue(boundary.length() >= 30);
        assertTrue(boundary.length() <= 40);

        NameValuePair p2 = elem.getParameterByName("charset");
        assertNull(p2);
    }
View Full Code Here


            throw new IllegalArgumentException("HTTP response may not be null");
        }
        HeaderElementIterator it = new BasicHeaderElementIterator(
                response.headerIterator(HTTP.CONN_KEEP_ALIVE));
        while (it.hasNext()) {
            HeaderElement he = it.nextElement();
            String param = he.getName();
            String value = he.getValue();
            if (value != null && param.equalsIgnoreCase("timeout")) {
                try {
                    return Long.parseLong(value) * 1000;
                } catch(NumberFormatException ignore) {
                }
View Full Code Here

            "name  = value; test; test1 =  stuff,with,commas   ; test2 =  \"stuff; stuff\"; test3=\"stuff";
        CharArrayBuffer buffer = new CharArrayBuffer(16);
        buffer.append(s);
        ParserCursor cursor = new ParserCursor(0, s.length());
       
        HeaderElement he = parser.parseHeader(buffer, cursor);
        assertEquals("name", he.getName());
        assertEquals("value", he.getValue());
        NameValuePair[] params = he.getParameters();
        assertEquals("test", params[0].getName());
        assertEquals(null, params[0].getValue());
        assertEquals("test1", params[1].getName());
        assertEquals("stuff,with,commas", params[1].getValue());
        assertEquals("test2", params[2].getName());
        assertEquals("stuff; stuff", params[2].getValue());
        assertEquals("test3", params[3].getName());
        assertEquals("\"stuff", params[3].getValue());
        assertEquals(s.length(), cursor.getPos());
        assertTrue(cursor.atEnd());

        s = "  ";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
        he = parser.parseHeader(buffer, cursor);
        assertEquals("", he.getName());
        assertEquals(null, he.getValue());
    }
View Full Code Here

        final HttpResponse result = impl.execute(route, req2, context, null);
        verifyMocks();

        if (HttpStatus.SC_PARTIAL_CONTENT == result.getStatusLine().getStatusCode()) {
            if (result.getFirstHeader("Content-Range") == null) {
                final HeaderElement elt = result.getFirstHeader("Content-Type").getElements()[0];
                Assert.assertTrue("multipart/byteranges".equalsIgnoreCase(elt.getName()));
                Assert.assertNotNull(elt.getParameterByName("boundary"));
                Assert.assertNotNull(elt.getParameterByName("boundary").getValue());
                Assert.assertFalse("".equals(elt.getParameterByName("boundary").getValue().trim()));
            }
        }
    }
View Full Code Here

    String charset = null;
    Header header = entity.getContentType();
    if (header != null) {
      HeaderElement[] helems = header.getElements();
      if (helems != null && helems.length > 0) {
        HeaderElement helem = helems[0];
        mimeType = helem.getName();
        NameValuePair nvp = helem.getParameterByName("charset");
        if (nvp != null) {
          charset = nvp.getValue();
        }
      }
    }
View Full Code Here

  public Map<String, Integer> getCacheControl() {
    Map<String, Integer> out = new HashMap<String, Integer>();
    HeaderElementIterator it = new BasicHeaderElementIterator(
        this.resp.headerIterator("Cache-Control"));
    while (it.hasNext()) {
        HeaderElement elem = it.nextElement();
        String elemName = elem.getName().toLowerCase();
        Integer v = null;
        if (elemName.equals("max-age") || elemName.equals("s-maxage")) {
          v = new Integer(elem.getValue());
        }
        out.put(elemName, v);
    }
    return out;
  }
View Full Code Here

        final HttpResponse result = impl.execute(route, req2);
        verifyMocks();

        if (HttpStatus.SC_PARTIAL_CONTENT == result.getStatusLine().getStatusCode()) {
            if (result.getFirstHeader("Content-Range") == null) {
                final HeaderElement elt = result.getFirstHeader("Content-Type").getElements()[0];
                Assert.assertTrue("multipart/byteranges".equalsIgnoreCase(elt.getName()));
                Assert.assertNotNull(elt.getParameterByName("boundary"));
                Assert.assertNotNull(elt.getParameterByName("boundary").getValue());
                Assert.assertFalse("".equals(elt.getParameterByName("boundary").getValue().trim()));
            }
        }
    }
View Full Code Here

      public long getKeepAliveDuration(HttpResponse response,
          HttpContext context) {
        HeaderElementIterator it = new BasicHeaderElementIterator(
            response.headerIterator(HTTP.CONN_KEEP_ALIVE));
        while (it.hasNext()) {
          HeaderElement he = it.nextElement();
          String param = he.getName();
          String value = he.getValue();
          if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
              return Long.parseLong(value) * 1000;
            } catch (NumberFormatException ignore) {
            }
View Full Code Here

      public long getKeepAliveDuration(HttpResponse response,
          HttpContext context) {
        HeaderElementIterator it = new BasicHeaderElementIterator(
            response.headerIterator(HTTP.CONN_KEEP_ALIVE));
        while (it.hasNext()) {
          HeaderElement he = it.nextElement();
          String param = he.getName();
          String value = he.getValue();
          if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
              return Long.parseLong(value) * 1000;
            } catch (NumberFormatException ignore) {
            }
View Full Code Here

        while (cur < indexTo) {
            char ch = buffer.charAt(cur);
            if (ch == '"' && !escaped) {
                qouted = !qouted;
            }
            HeaderElement element = null;
            if ((!qouted) && (ch == ',')) {
                element = parse(buffer, from, cur);
                from = cur + 1;
            } else if (cur == indexTo - 1) {
                element = parse(buffer, from, indexTo);
            }
            if (element != null && !(element.getName().length() == 0 && element.getValue() == null)) {
                elements.add(element);
            }
            if (escaped) {
                escaped = false;
            } else {
View Full Code Here

TOP

Related Classes of org.apache.http.HeaderElement

Copyright © 2018 www.massapicom. 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.