001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2010–2011 ApexIdentity Inc.
015 * Portions Copyright 2011-2014 ForgeRock AS.
016 */
017
018package org.forgerock.openig.http;
019
020
021/**
022 * Utility class for processing HTTP messages.
023 */
024public final class HttpUtil {
025
026    /** Static methods only. */
027    private HttpUtil() {
028    }
029
030    /**
031     * Returns the example reason phrase for the corresponding status code, per
032     * RFC 2616 §6.1.1. If the status code is unrecognized, then {@code null} is returned.
033     *
034     * @param status the status code from which to derive the reason phrase.
035     * @return the reason phrase corresponding to the specified status code.
036     */
037    public static String getReason(int status) {
038        switch (status) {
039        case 100:
040            return "Continue";
041        case 101:
042            return "Switching Protocols";
043        case 200:
044            return "OK";
045        case 201:
046            return "Created";
047        case 202:
048            return "Accepted";
049        case 203:
050            return "Non-Authoritative Information";
051        case 204:
052            return "No Content";
053        case 205:
054            return "Reset Content";
055        case 206:
056            return "Partial Content";
057        case 300:
058            return "Multiple Choices";
059        case 301:
060            return "Moved Permanently";
061        case 302:
062            return "Found";
063        case 303:
064            return "See Other";
065        case 304:
066            return "Not Modified";
067        case 305:
068            return "Use Proxy";
069        case 307:
070            return "Temporary Redirect";
071        case 400:
072            return "Bad Request";
073        case 401:
074            return "Unauthorized";
075        case 402:
076            return "Payment Required";
077        case 403:
078            return "Forbidden";
079        case 404:
080            return "Not Found";
081        case 405:
082            return "Method Not Allowed";
083        case 406:
084            return "Not Acceptable";
085        case 407:
086            return "Proxy Authentication Required";
087        case 408:
088            return "Request Time-out";
089        case 409:
090            return "Conflict";
091        case 410:
092            return "Gone";
093        case 411:
094            return "Length Required";
095        case 412:
096            return "Precondition Failed";
097        case 413:
098            return "Request Entity Too Large";
099        case 414:
100            return "Request-URI Too Large";
101        case 415:
102            return "Unsupported Media Type";
103        case 416:
104            return "Requested range not satisfiable";
105        case 417:
106            return "Expectation Failed";
107        case 500:
108            return "Internal Server Error";
109        case 501:
110            return "Not Implemented";
111        case 502:
112            return "Bad Gateway";
113        case 503:
114            return "Service Unavailable";
115        case 504:
116            return "Gateway Time-out";
117        case 505:
118            return "HTTP Version not supported";
119        }
120        return null; // not specified per RFC 2616
121    }
122}