use of com.parse.http.ParseHttpRequest in project Parse-SDK-Android by ParsePlatform.
the class ParseRESTCommand method newRequest.
@Override
protected ParseHttpRequest newRequest(ParseHttpRequest.Method method, String url, ProgressCallback uploadProgressCallback) {
ParseHttpRequest request;
if (jsonParameters != null && method != ParseHttpRequest.Method.POST && method != ParseHttpRequest.Method.PUT) {
// The request URI may be too long to include parameters in the URI.
// To avoid this problem we send the parameters in a POST request json-encoded body
// and add a http method override parameter in newBody.
request = super.newRequest(ParseHttpRequest.Method.POST, url, uploadProgressCallback);
} else {
request = super.newRequest(method, url, uploadProgressCallback);
}
ParseHttpRequest.Builder requestBuilder = new ParseHttpRequest.Builder(request);
addAdditionalHeaders(requestBuilder);
return requestBuilder.build();
}
use of com.parse.http.ParseHttpRequest in project Parse-SDK-Android by ParsePlatform.
the class ParseHttpClient method getRequest.
Request getRequest(ParseHttpRequest parseRequest) {
Request.Builder okHttpRequestBuilder = new Request.Builder();
ParseHttpRequest.Method method = parseRequest.getMethod();
// Set method
switch(method) {
case GET:
okHttpRequestBuilder.get();
break;
case DELETE:
case POST:
case PUT:
// the following.
break;
default:
// ParseRequest.newRequest().
throw new IllegalStateException("Unsupported http method " + method.toString());
}
// Set url
okHttpRequestBuilder.url(parseRequest.getUrl());
// Set Header
Headers.Builder okHttpHeadersBuilder = new Headers.Builder();
for (Map.Entry<String, String> entry : parseRequest.getAllHeaders().entrySet()) {
okHttpHeadersBuilder.add(entry.getKey(), entry.getValue());
}
// OkHttp automatically add gzip header so we do not need to deal with it
Headers okHttpHeaders = okHttpHeadersBuilder.build();
okHttpRequestBuilder.headers(okHttpHeaders);
// Set Body
ParseHttpBody parseBody = parseRequest.getBody();
ParseOkHttpRequestBody okHttpRequestBody = null;
if (parseBody != null) {
okHttpRequestBody = new ParseOkHttpRequestBody(parseBody);
}
switch(method) {
case PUT:
okHttpRequestBuilder.put(okHttpRequestBody);
break;
case POST:
okHttpRequestBuilder.post(okHttpRequestBody);
break;
case DELETE:
okHttpRequestBuilder.delete(okHttpRequestBody);
}
return okHttpRequestBuilder.build();
}
Aggregations