HttpURI.st
author Stefan Vogel <sv@exept.de>
Mon, 20 Feb 2017 10:41:32 +0100
changeset 4337 167d0c973942
parent 2870 6eef483653e5
child 4722 fe159f4a0668
permissions -rw-r--r--
#BUGFIX by stefan class: Promise changed: #initialize #value: #value:priority: Use EventSemaphore. Do not do double initialization.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1309
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
     1
"
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
     2
 COPYRIGHT (c) 2002 by eXept Software AG
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
     3
              All Rights Reserved
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
     4
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
     5
 This software is furnished under a license and may be used
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
     6
 only in accordance with the terms of that license and with the
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
     8
 be provided or otherwise made available to, or used by, any
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
     9
 other person.  No title to or ownership of the software is
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    10
 hereby transferred.
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    11
"
1005
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    13
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    14
HierarchicalURI subclass:#HttpURI
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:''
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    16
	classVariableNames:''
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
1310
948ed141b0b7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
    18
	category:'Net-Resources'
1005
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    19
!
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    20
1309
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    21
!HttpURI class methodsFor:'documentation'!
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    22
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    23
copyright
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    24
"
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    25
 COPYRIGHT (c) 2002 by eXept Software AG
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    26
              All Rights Reserved
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    27
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    28
 This software is furnished under a license and may be used
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    29
 only in accordance with the terms of that license and with the
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    31
 be provided or otherwise made available to, or used by, any
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    32
 other person.  No title to or ownership of the software is
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    33
 hereby transferred.
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    34
"
c752d54f4e09 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
    35
! !
1005
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    36
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    37
!HttpURI class methodsFor:'accessing'!
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    38
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    39
schemes
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    40
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    41
    ^ #(http)
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    42
! !
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    43
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    44
!HttpURI methodsFor:'defaults'!
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    45
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    46
defaultPort
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    47
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    48
    ^ 80
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    49
! !
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    50
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    51
!HttpURI methodsFor:'stream access'!
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    52
2870
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    53
contents
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    54
    "use HTTPInterface for now"
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    55
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    56
    |response|
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    57
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    58
    response := HTTPInterface get:self path 
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    59
                    fromHost:self host 
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    60
                    port:self port
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    61
                    accept:#('*/*')  
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    62
                    fromDocument:nil.
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    63
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    64
    response isErrorResponse 
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    65
        ifTrue:[ self error: response responseText ].
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    66
    ^ response data
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    67
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    68
    "
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    69
     'http://www.puzzlers.org/pub/wordlists/unixdict.txt' asURI contents
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    70
    "
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    71
!
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    72
1005
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    73
readStreamDo:aBlock
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    74
    "use HTTPInterface for now"
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    75
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    76
    |response headerInfo mime|
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    77
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    78
    response := HTTPInterface get:self path 
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    79
                    fromHost:self host 
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    80
                    port:self port
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    81
                    accept:#('*/*')  
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    82
                    fromDocument:nil.
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    83
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    84
    headerInfo := response headerInfo.
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    85
    mime := headerInfo at:'content-type' ifAbsent:nil.
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    86
    mime notNil ifTrue:[
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    87
        headerInfo at:#MIME put:mime.
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    88
    ].
2870
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    89
    aBlock value:response data readStream optionalArgument:headerInfo
1005
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    90
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    91
    "
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    92
     'http://www.exept.de/' asURI readStreamDo:[:stream :attributes | 
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    93
         self halt
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    94
      ].
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    95
    "
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    96
! !
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    97
1276
fd3f0d37513c Print without password.
Stefan Vogel <sv@exept.de>
parents: 1005
diff changeset
    98
!HttpURI methodsFor:'testing'!
fd3f0d37513c Print without password.
Stefan Vogel <sv@exept.de>
parents: 1005
diff changeset
    99
1461
998d6076f34d Fix absolute UR handling
Stefan Vogel <sv@exept.de>
parents: 1310
diff changeset
   100
isAbsolute
998d6076f34d Fix absolute UR handling
Stefan Vogel <sv@exept.de>
parents: 1310
diff changeset
   101
    "there is nothing like a relative http URI"
998d6076f34d Fix absolute UR handling
Stefan Vogel <sv@exept.de>
parents: 1310
diff changeset
   102
998d6076f34d Fix absolute UR handling
Stefan Vogel <sv@exept.de>
parents: 1310
diff changeset
   103
    ^ true
998d6076f34d Fix absolute UR handling
Stefan Vogel <sv@exept.de>
parents: 1310
diff changeset
   104
!
998d6076f34d Fix absolute UR handling
Stefan Vogel <sv@exept.de>
parents: 1310
diff changeset
   105
1276
fd3f0d37513c Print without password.
Stefan Vogel <sv@exept.de>
parents: 1005
diff changeset
   106
isRemote
fd3f0d37513c Print without password.
Stefan Vogel <sv@exept.de>
parents: 1005
diff changeset
   107
    "return true, if this is a remote URI"
fd3f0d37513c Print without password.
Stefan Vogel <sv@exept.de>
parents: 1005
diff changeset
   108
fd3f0d37513c Print without password.
Stefan Vogel <sv@exept.de>
parents: 1005
diff changeset
   109
    ^ true
fd3f0d37513c Print without password.
Stefan Vogel <sv@exept.de>
parents: 1005
diff changeset
   110
! !
fd3f0d37513c Print without password.
Stefan Vogel <sv@exept.de>
parents: 1005
diff changeset
   111
1005
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   112
!HttpURI class methodsFor:'documentation'!
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   113
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   114
version
2870
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
   115
    ^ '$Header: /cvs/stx/stx/libbasic2/HttpURI.st,v 1.6 2013-01-20 15:22:18 cg Exp $'
1005
7ed6fa7ccfba initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   116
! !
2870
6eef483653e5 class: HttpURI
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
   117