Esempio n. 1
0
 private Bundle bundleFromResponse()
 {
     return(HttpUtil.BundleResponse(LastResponseDetails.BodyAsString(), LastResponseDetails.ContentType));
 }
Esempio n. 2
0
 private ResourceEntry <T> makeEntryFromHeaders <T>(T resource) where T : Resource, new()
 {
     return((ResourceEntry <T>)HttpUtil.CreateResourceEntryFromResource(resource,
                                                                        LastResponseDetails.Location ?? LastResponseDetails.ContentLocation,
                                                                        LastResponseDetails.Category, LastResponseDetails.LastModified));
 }
Esempio n. 3
0
 private TagList tagListFromResponse()
 {
     return(HttpUtil.TagListResponse(LastResponseDetails.BodyAsString(), LastResponseDetails.ContentType));
 }
Esempio n. 4
0
 private static byte[] readBody(HttpWebResponse response)
 {
     return(HttpUtil.ReadAllFromStream(response.GetResponseStream(),
                                       (int)response.ContentLength));
 }
        public static HttpWebRequest ToHttpRequest(this Bundle.EntryComponent entry, Uri baseUrl,
                                                   Prefer bodyPreference, ResourceFormat format, bool useFormatParameter, bool CompressRequestBody, out byte[] body)
        {
            System.Diagnostics.Debug.WriteLine("{0}: {1}", entry.Request.Method, entry.Request.Url);

            var interaction = entry.Request;

            body = null;

            if (entry.Resource != null && !(interaction.Method == Bundle.HTTPVerb.POST || interaction.Method == Bundle.HTTPVerb.PUT))
            {
                throw Error.InvalidOperation("Cannot have a body on an Http " + interaction.Method.ToString());
            }

            // Create an absolute uri when the interaction.Url is relative.
            var uri = new Uri(interaction.Url, UriKind.RelativeOrAbsolute);

            if (!uri.IsAbsoluteUri)
            {
                uri = HttpUtil.MakeAbsoluteToBase(uri, baseUrl);
            }
            var location = new RestUrl(uri);

            if (useFormatParameter)
            {
                location.AddParam(HttpUtil.RESTPARAM_FORMAT, Hl7.Fhir.Rest.ContentType.BuildFormatParam(format));
            }

            var request = (HttpWebRequest)HttpWebRequest.Create(location.Uri);

            request.Method = interaction.Method.ToString();
            setAgent(request, ".NET FhirClient for FHIR " + Model.ModelInfo.Version);

            if (!useFormatParameter)
            {
                request.Accept = Hl7.Fhir.Rest.ContentType.BuildContentType(format, forBundle: false);
            }

            if (interaction.IfMatch != null)
            {
                request.Headers["If-Match"] = interaction.IfMatch;
            }
            if (interaction.IfNoneMatch != null)
            {
                request.Headers["If-None-Match"] = interaction.IfNoneMatch;
            }
#if NETSTANDARD1_1
            if (interaction.IfModifiedSince != null)
            {
                request.Headers["If-Modified-Since"] = interaction.IfModifiedSince.Value.UtcDateTime.ToString();
            }
#else
            if (interaction.IfModifiedSince != null)
            {
                request.IfModifiedSince = interaction.IfModifiedSince.Value.UtcDateTime;
            }
#endif
            if (interaction.IfNoneExist != null)
            {
                request.Headers["If-None-Exist"] = interaction.IfNoneExist;
            }

            if (interaction.Method == Bundle.HTTPVerb.POST || interaction.Method == Bundle.HTTPVerb.PUT)
            {
                request.Headers["Prefer"] = bodyPreference == Prefer.ReturnMinimal ? "return=minimal" : "return=representation";
            }

            if (entry.Resource != null)
            {
                bool searchUsingPost =
                    interaction.Method == Bundle.HTTPVerb.POST &&
                    (entry.HasAnnotation <TransactionBuilder.InteractionType>() &&
                     entry.Annotation <TransactionBuilder.InteractionType>() == TransactionBuilder.InteractionType.Search) &&
                    entry.Resource is Parameters;

                setBodyAndContentType(request, entry.Resource, format, CompressRequestBody, searchUsingPost, out body);
            }
            // PCL doesn't support setting the length (and in this case will be empty anyway)
#if !NETSTANDARD1_1
            else
            {
                request.ContentLength = 0;
            }
#endif
            return(request);
        }
 public static bool IsRestResourceIdentity(string url)
 {
     return(HttpUtil.IsRestResourceIdentity(url));
 }