use of org.apache.http.ProtocolVersion in project android-uploader by nightscout.
the class RestLegacyUploaderTest method setUpExecuteCaptor.
public void setUpExecuteCaptor(int status) throws IOException {
captor = ArgumentCaptor.forClass(HttpUriRequest.class);
HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("mock", 1, 2), status, ""));
response.setEntity(new StringEntity(""));
when(mockHttpClient.execute(captor.capture())).thenReturn(response);
}
use of org.apache.http.ProtocolVersion in project robovm by robovm.
the class BasicLineParser method parseStatusLine.
// non-javadoc, see interface LineParser
public StatusLine parseStatusLine(final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException {
if (buffer == null) {
throw new IllegalArgumentException("Char array buffer may not be null");
}
if (cursor == null) {
throw new IllegalArgumentException("Parser cursor may not be null");
}
int indexFrom = cursor.getPos();
int indexTo = cursor.getUpperBound();
try {
// handle the HTTP-Version
ProtocolVersion ver = parseProtocolVersion(buffer, cursor);
// handle the Status-Code
skipWhitespace(buffer, cursor);
int i = cursor.getPos();
int blank = buffer.indexOf(' ', i, indexTo);
if (blank < 0) {
blank = indexTo;
}
int statusCode = 0;
try {
statusCode = Integer.parseInt(buffer.substringTrimmed(i, blank));
} catch (NumberFormatException e) {
throw new ParseException("Unable to parse status code from status line: " + buffer.substring(indexFrom, indexTo));
}
//handle the Reason-Phrase
i = blank;
String reasonPhrase = null;
if (i < indexTo) {
reasonPhrase = buffer.substringTrimmed(i, indexTo);
} else {
reasonPhrase = "";
}
return createStatusLine(ver, statusCode, reasonPhrase);
} catch (IndexOutOfBoundsException e) {
throw new ParseException("Invalid status line: " + buffer.substring(indexFrom, indexTo));
}
}
use of org.apache.http.ProtocolVersion in project robovm by robovm.
the class HttpRequestExecutor method doSendRequest.
/**
* Send a request over a connection.
* This method also handles the expect-continue handshake if necessary.
* If it does not have to handle an expect-continue handshake, it will
* not use the connection for reading or anything else that depends on
* data coming in over the connection.
*
* @param request the request to send, already
* {@link #preProcess preprocessed}
* @param conn the connection over which to send the request,
* already established
* @param context the context for sending the request
*
* @return a terminal response received as part of an expect-continue
* handshake, or
* <code>null</code> if the expect-continue handshake is not used
*
* @throws HttpException in case of a protocol or processing problem
* @throws IOException in case of an I/O problem
*/
protected HttpResponse doSendRequest(final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws IOException, HttpException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (conn == null) {
throw new IllegalArgumentException("HTTP connection may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
HttpResponse response = null;
context.setAttribute(ExecutionContext.HTTP_REQ_SENT, Boolean.FALSE);
conn.sendRequestHeader(request);
if (request instanceof HttpEntityEnclosingRequest) {
// Check for expect-continue handshake. We have to flush the
// headers and wait for an 100-continue response to handle it.
// If we get a different response, we must not send the entity.
boolean sendentity = true;
final ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
if (((HttpEntityEnclosingRequest) request).expectContinue() && !ver.lessEquals(HttpVersion.HTTP_1_0)) {
conn.flush();
// As suggested by RFC 2616 section 8.2.3, we don't wait for a
// 100-continue response forever. On timeout, send the entity.
int tms = request.getParams().getIntParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE, 2000);
if (conn.isResponseAvailable(tms)) {
response = conn.receiveResponseHeader();
if (canResponseHaveBody(request, response)) {
conn.receiveResponseEntity(response);
}
int status = response.getStatusLine().getStatusCode();
if (status < 200) {
if (status != HttpStatus.SC_CONTINUE) {
throw new ProtocolException("Unexpected response: " + response.getStatusLine());
}
// discard 100-continue
response = null;
} else {
sendentity = false;
}
}
}
if (sendentity) {
conn.sendRequestEntity((HttpEntityEnclosingRequest) request);
}
}
conn.flush();
context.setAttribute(ExecutionContext.HTTP_REQ_SENT, Boolean.TRUE);
return response;
}
use of org.apache.http.ProtocolVersion in project robovm by robovm.
the class BasicHttpResponse method setStatusCode.
// non-javadoc, see interface HttpResponse
public void setStatusCode(int code) {
// argument checked in BasicStatusLine constructor
ProtocolVersion ver = this.statusline.getProtocolVersion();
this.statusline = new BasicStatusLine(ver, code, getReason(code));
}
use of org.apache.http.ProtocolVersion in project robovm by robovm.
the class DefaultRequestDirector method createConnectRequest.
/**
* Creates the CONNECT request for tunnelling.
* Called by {@link #createTunnelToTarget createTunnelToTarget}.
*
* @param route the route to establish
* @param context the context for request execution
*
* @return the CONNECT request for tunnelling
*/
protected HttpRequest createConnectRequest(HttpRoute route, HttpContext context) {
// see RFC 2817, section 5.2 and
// INTERNET-DRAFT: Tunneling TCP based protocols through
// Web proxy servers
HttpHost target = route.getTargetHost();
String host = target.getHostName();
int port = target.getPort();
if (port < 0) {
Scheme scheme = connManager.getSchemeRegistry().getScheme(target.getSchemeName());
port = scheme.getDefaultPort();
}
StringBuilder buffer = new StringBuilder(host.length() + 6);
buffer.append(host);
buffer.append(':');
buffer.append(Integer.toString(port));
String authority = buffer.toString();
ProtocolVersion ver = HttpProtocolParams.getVersion(params);
HttpRequest req = new BasicHttpRequest("CONNECT", authority, ver);
return req;
}
Aggregations