Ejemplo n.º 1
0
 public HttpResponseBuilder(sResponse response)
 {
     httpStatusCode = response.getHttpStatusCode();
     headers.Add(response.getHeaders());
     foreach (var item in response.getMetadata())
     {
         metadata.Add(item.Key, item.Value);
     }
     responseBytes = response.responseBytes;
 }
Ejemplo n.º 2
0
 public HttpResponseBuilder(sResponse response)
 {
     httpStatusCode = response.getHttpStatusCode();
     headers.Add(response.getHeaders());
     foreach (var item in response.getMetadata())
     {
         metadata.Add(item.Key, item.Value);
     }
     responseBytes = response.responseBytes;
 }
Ejemplo n.º 3
0
  /**
 * Convert a response to a JSON object.  static so it can be used by HttpPreloaders as well.
 * 
 * The returned JSON object contains the following values:
 * rc: integer response code
 * body: string response body
 * headers: object, keys are header names, values are lists of header values
 * 
 * @param response the response body
 * @param body string to use as the body of the response.
 * @return a JSONObject representation of the response body.
 */
  public static JsonObject getResponseAsJson(sResponse response, String body)
  {
      JsonObject resp = new JsonObject();
      resp.Put("rc", response.getHttpStatusCode());
      resp.Put("body", body);
      JsonObject headers = new JsonObject();
      addHeaders(headers, response, "set-cookie");
      addHeaders(headers, response, "location");
      resp.Put("headers", headers);
      // Merge in additional response data
      foreach (var entry in response.getMetadata())
      {
          resp.Put(entry.Key, entry.Value);
      }
      return resp;
  }
Ejemplo n.º 4
0
 /**
 * Check if a response might be due to an OAuth protocol error.  We don't want to intercept
 * errors for signed fetch, we only care about places where we are dealing with OAuth request
 * and/or access tokens.
 */
 private bool isFullOAuthError(sResponse response)
 {
     // 400, 401 and 403 are likely to be authentication errors.
     if (response.getHttpStatusCode() != 400 && response.getHttpStatusCode() != 401 &&
         response.getHttpStatusCode() != 403)
     {
         return false;
     }
     // If the client forced us to use full OAuth, this might be OAuth related.
     if (realRequest.getOAuthArguments().mustUseToken())
     {
         return true;
     }
     // If we're using an access token, this might be OAuth related.
     if (accessorInfo.getAccessor().accessToken != null)
     {
         return true;
     }
     // Not OAuth related.
     return false;
 }
Ejemplo n.º 5
0
 /**
 * Look for an OAuth protocol problem.  For cases where no access token is in play 
 * @param response
 * @throws OAuthProtocolException
 * @throws IOException
 */
 private void checkForProtocolProblem(sResponse response)
 {
     if (isFullOAuthError(response))
     {
         OAuthMessage message = parseAuthHeader(null, response);
         if (message.getParameter(OAuthProblemException.OAUTH_PROBLEM) != null)
         {
             // SP reported extended error information
             throw new OAuthProtocolException(message);
         }
         // No extended information, guess based on HTTP response code.
         throw new OAuthProtocolException(response.getHttpStatusCode());
     }
 }